Stub for object
This commit is contained in:
@@ -33,7 +33,7 @@ public interface JetNodeTypes {
|
||||
IElementType PROPERTY = JetStubElementTypes.PROPERTY;
|
||||
|
||||
JetNodeType TYPEDEF = new JetNodeType("TYPEDEF", JetTypedef.class);
|
||||
JetNodeType OBJECT_DECLARATION = new JetNodeType("OBJECT_DECLARATION", JetObjectDeclaration.class);
|
||||
IElementType OBJECT_DECLARATION = JetStubElementTypes.OBJECT_DECLARATION;
|
||||
JetNodeType OBJECT_DECLARATION_NAME = new JetNodeType("OBJECT_DECLARATION_NAME", JetObjectDeclarationName.class);
|
||||
|
||||
JetNodeType CLASS_OBJECT = new JetNodeType("CLASS_OBJECT", JetClassObject.class);
|
||||
|
||||
@@ -18,11 +18,15 @@ package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.stubs.IStubElementType;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetObjectStub;
|
||||
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -31,17 +35,45 @@ import java.util.List;
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class JetObjectDeclaration extends JetNamedDeclarationNotStubbed implements JetClassOrObject {
|
||||
public class JetObjectDeclaration extends JetNamedDeclarationStub<PsiJetObjectStub> implements JetClassOrObject {
|
||||
public JetObjectDeclaration(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
public JetObjectDeclaration(@NotNull PsiJetObjectStub stub) {
|
||||
super(stub, JetStubElementTypes.OBJECT_DECLARATION);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public IStubElementType getElementType() {
|
||||
return JetStubElementTypes.OBJECT_DECLARATION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
PsiJetObjectStub stub = getStub();
|
||||
if (stub != null) {
|
||||
return stub.getName();
|
||||
}
|
||||
|
||||
JetObjectDeclarationName nameAsDeclaration = getNameAsDeclaration();
|
||||
return nameAsDeclaration == null ? null : nameAsDeclaration.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Could be null for anonymous objects and object declared inside functions
|
||||
* @return
|
||||
*/
|
||||
public FqName getFqName() {
|
||||
PsiJetObjectStub stub = getStub();
|
||||
if (stub != null) {
|
||||
return stub.getFQName();
|
||||
}
|
||||
|
||||
return JetPsiUtil.getFQName(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement getNameIdentifier() {
|
||||
JetObjectDeclarationName nameAsDeclaration = getNameAsDeclaration();
|
||||
|
||||
@@ -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.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetObjectDeclaration;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public interface PsiJetObjectStub extends NamedStub<JetObjectDeclaration> {
|
||||
@NotNull
|
||||
FqName getFQName();
|
||||
}
|
||||
+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.psi.PsiElement;
|
||||
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.JetObjectDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetObjectStub;
|
||||
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetObjectStubImpl;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public class JetObjectElementType extends JetStubElementType<PsiJetObjectStub, JetObjectDeclaration> {
|
||||
public JetObjectElementType(@NotNull @NonNls String debugName) {
|
||||
super(debugName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetObjectDeclaration createPsiFromAst(@NotNull ASTNode node) {
|
||||
return new JetObjectDeclaration(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetObjectDeclaration createPsi(@NotNull PsiJetObjectStub stub) {
|
||||
return new JetObjectDeclaration(stub);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCreateStub(ASTNode node) {
|
||||
if (super.shouldCreateStub(node)) {
|
||||
PsiElement psiElement = node.getPsi();
|
||||
if (psiElement instanceof JetObjectDeclaration) {
|
||||
JetObjectDeclaration objectDeclaration = (JetObjectDeclaration) psiElement;
|
||||
return objectDeclaration.getName() != null && objectDeclaration.getFqName() != null;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiJetObjectStub createStub(@NotNull JetObjectDeclaration psi, @NotNull StubElement parentStub) {
|
||||
String name = psi.getName();
|
||||
assert name != null;
|
||||
|
||||
FqName fqName = psi.getFqName();
|
||||
assert fqName != null;
|
||||
|
||||
return new PsiJetObjectStubImpl(JetStubElementTypes.OBJECT_DECLARATION, parentStub, name, fqName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(PsiJetObjectStub stub, StubOutputStream dataStream) throws IOException {
|
||||
dataStream.writeName(stub.getName());
|
||||
dataStream.writeName(stub.getFQName().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiJetObjectStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException {
|
||||
StringRef name = dataStream.readName();
|
||||
StringRef fqNameStr = dataStream.readName();
|
||||
FqName fqName = new FqName(fqNameStr.toString());
|
||||
|
||||
return new PsiJetObjectStubImpl(JetStubElementTypes.OBJECT_DECLARATION, parentStub, name, fqName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void indexStub(PsiJetObjectStub stub, IndexSink sink) {
|
||||
StubIndexServiceFactory.getInstance().indexObject(stub, sink);
|
||||
}
|
||||
}
|
||||
+1
@@ -26,6 +26,7 @@ public interface JetStubElementTypes {
|
||||
JetFunctionElementType FUNCTION = new JetFunctionElementType("FUN");
|
||||
JetPropertyElementType PROPERTY = new JetPropertyElementType("PROPERTY");
|
||||
JetClassElementType ENUM_ENTRY = new JetClassElementType("ENUM_ENTRY");
|
||||
JetObjectElementType OBJECT_DECLARATION = new JetObjectElementType("OBJECT_DECLARATION");
|
||||
|
||||
JetParameterElementType VALUE_PARAMETER = new JetParameterElementType("VALUE_PARAMETER");
|
||||
JetParameterListElementType VALUE_PARAMETER_LIST = new JetParameterListElementType("VALUE_PARAMETER_LIST");
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.jet.lang.psi.stubs.elements;
|
||||
import com.intellij.psi.stubs.IndexSink;
|
||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub;
|
||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetFunctionStub;
|
||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetObjectStub;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
@@ -36,8 +37,13 @@ public interface StubIndexService {
|
||||
@Override
|
||||
public void indexFunction(PsiJetFunctionStub stub, IndexSink sink) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void indexObject(PsiJetObjectStub stub, IndexSink sink) {
|
||||
}
|
||||
};
|
||||
|
||||
void indexClass(PsiJetClassStub stub, IndexSink sink);
|
||||
void indexFunction(PsiJetFunctionStub stub, IndexSink sink);
|
||||
void indexObject(PsiJetObjectStub stub, IndexSink sink);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetObjectDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetObjectStub;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public class PsiJetObjectStubImpl extends StubBase<JetObjectDeclaration> implements PsiJetObjectStub {
|
||||
private final StringRef name;
|
||||
private final FqName fqName;
|
||||
|
||||
public PsiJetObjectStubImpl(
|
||||
@NotNull IStubElementType elementType,
|
||||
@NotNull StubElement parent,
|
||||
@NotNull String name,
|
||||
@NotNull FqName fqName) {
|
||||
this(elementType, parent, StringRef.fromString(name), fqName);
|
||||
}
|
||||
|
||||
public PsiJetObjectStubImpl(
|
||||
@NotNull IStubElementType elementType,
|
||||
@NotNull StubElement parent,
|
||||
@NotNull StringRef name,
|
||||
@NotNull FqName fqName) {
|
||||
super(parent, elementType);
|
||||
|
||||
this.name = name;
|
||||
this.fqName = fqName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return StringRef.toString(name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FqName getFQName() {
|
||||
return fqName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("PsiJetObjectStubImpl[");
|
||||
builder.append("name=").append(getName());
|
||||
builder.append(" fqName=").append(getFQName().toString());
|
||||
builder.append("]");
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import java.util.Collection;
|
||||
*/
|
||||
public class JetAllShortFunctionNameIndex extends StringStubIndexExtension<JetNamedFunction> {
|
||||
private static final JetShortClassNameIndex ourInstance = new JetShortClassNameIndex();
|
||||
|
||||
public static JetShortClassNameIndex getInstance() {
|
||||
return ourInstance;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,6 @@ public class JetExtensionFunctionNameIndex extends StringStubIndexExtension<JetN
|
||||
@NotNull
|
||||
@Override
|
||||
public StubIndexKey<String, JetNamedFunction> getKey() {
|
||||
return JetIndexKeys.EXTENSION_FUNCTION_SHORT_NAME_KEY;
|
||||
return JetIndexKeys.TOP_LEVEL_EXTENSION_FUNCTION_SHORT_NAME_KEY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ import java.util.Collection;
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public class JetFullClassNameIndex extends StringStubIndexExtension<JetClassOrObject> {
|
||||
|
||||
private static final JetFullClassNameIndex ourInstance = new JetFullClassNameIndex();
|
||||
|
||||
public static JetFullClassNameIndex getInstance() {
|
||||
return ourInstance;
|
||||
}
|
||||
|
||||
@@ -29,10 +29,9 @@ public interface JetIndexKeys {
|
||||
StubIndexKey<String, JetClassOrObject> FQN_KEY = StubIndexKey.createIndexKey("jet.fqn");
|
||||
|
||||
StubIndexKey<String, JetNamedFunction> TOP_LEVEL_FUNCTION_SHORT_NAME_KEY = StubIndexKey.createIndexKey("jet.top.level.function.short.name");
|
||||
StubIndexKey<String, JetNamedFunction> TOP_LEVEL_FUNCTION_FQNAME_KEY = StubIndexKey.createIndexKey("jet.top.level.function.fqname");
|
||||
StubIndexKey<String, JetNamedFunction> TOP_LEVEL_EXTENSION_FUNCTION_SHORT_NAME_KEY = StubIndexKey.createIndexKey("jet.top.level.extension.function.short.name");
|
||||
|
||||
StubIndexKey<String, JetNamedFunction> EXTENSION_FUNCTION_SHORT_NAME_KEY = StubIndexKey.createIndexKey("jet.top.level.extension.function.short.name");
|
||||
StubIndexKey<String, JetNamedFunction> EXTENSION_FUNCTION_FQNAME_KEY = StubIndexKey.createIndexKey("jet.top.level.extension.function.fqname");
|
||||
StubIndexKey<String, JetNamedFunction> TOP_LEVEL_FUNCTIONS_FQN_NAME_KEY = StubIndexKey.createIndexKey("jet.top.level.functions.fqn.name");
|
||||
|
||||
StubIndexKey<String, JetNamedFunction> FUNCTIONS_SHORT_NAME_KEY = StubIndexKey.createIndexKey("jet.functions.short.name");
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.util.Collection;
|
||||
*/
|
||||
public class JetShortClassNameIndex extends StringStubIndexExtension<JetClassOrObject> {
|
||||
private static final JetShortClassNameIndex ourInstance = new JetShortClassNameIndex();
|
||||
|
||||
public static JetShortClassNameIndex getInstance() {
|
||||
return ourInstance;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.jet.plugin.stubindex;
|
||||
import com.intellij.psi.stubs.IndexSink;
|
||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub;
|
||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetFunctionStub;
|
||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetObjectStub;
|
||||
import org.jetbrains.jet.lang.psi.stubs.elements.StubIndexService;
|
||||
|
||||
/**
|
||||
@@ -43,6 +44,15 @@ public class StubIndexServiceImpl implements StubIndexService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void indexObject(PsiJetObjectStub stub, IndexSink sink) {
|
||||
String name = stub.getName();
|
||||
assert name != null;
|
||||
|
||||
sink.occurrence(JetIndexKeys.SHORT_NAME_KEY, name);
|
||||
sink.occurrence(JetIndexKeys.FQN_KEY, stub.getFQName().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void indexFunction(PsiJetFunctionStub stub, IndexSink sink) {
|
||||
String name = stub.getName();
|
||||
@@ -54,12 +64,13 @@ public class StubIndexServiceImpl implements StubIndexService {
|
||||
// sink.occurrence(JetIndexKeys.TOP_LEVEL_FUNCTION_FQNAME_KEY, name);
|
||||
}
|
||||
else {
|
||||
sink.occurrence(JetIndexKeys.EXTENSION_FUNCTION_SHORT_NAME_KEY, name);
|
||||
sink.occurrence(JetIndexKeys.TOP_LEVEL_EXTENSION_FUNCTION_SHORT_NAME_KEY, name);
|
||||
// sink.occurrence(JetIndexKeys.EXTENSION_FUNCTION_FQNAME_KEY, name);
|
||||
}
|
||||
}
|
||||
|
||||
sink.occurrence(JetIndexKeys.FUNCTIONS_SHORT_NAME_KEY, name);
|
||||
// sink.occurrence(JetIndexKeys.FUNCTIONS_FQN_NAME_KEY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,6 +136,12 @@ public class JetStubsTest extends LightCodeInsightFixtureTestCase {
|
||||
" TYPE_PARAMETER_LIST:PsiJetTypeParameterListStubImpl\n");
|
||||
}
|
||||
|
||||
public void testNamedObject() {
|
||||
doBuildTest("object Test {}",
|
||||
"PsiJetFileStubImpl[package=]\n" +
|
||||
" OBJECT_DECLARATION:PsiJetObjectStubImpl[name=Test fqName=Test]\n");
|
||||
}
|
||||
|
||||
private void doBuildTest(@NonNls final String source, @NonNls @NotNull final String tree) {
|
||||
final JetFile file = (JetFile) createLightFile(JetFileType.INSTANCE, source);
|
||||
final FileASTNode fileNode = file.getNode();
|
||||
|
||||
Reference in New Issue
Block a user