Drop JetClassObject element and its usages

as class objects are now represented by JetObjectDeclaration element
This commit is contained in:
Pavel V. Talanov
2015-01-21 14:44:18 +03:00
parent be7f5d01bb
commit d9d3f68a39
47 changed files with 87 additions and 411 deletions
@@ -155,7 +155,7 @@ public class JetIconProvider extends IconProvider implements DumbAware {
}
return icon;
}
if (psiElement instanceof JetObjectDeclaration || psiElement instanceof JetClassObject) {
if (psiElement instanceof JetObjectDeclaration) {
return JetIcons.OBJECT;
}
if (psiElement instanceof JetParameter) {
@@ -29,7 +29,6 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.stubs.StringStubIndexExtension;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.containers.ContainerUtil;
import gnu.trove.THashSet;
import kotlin.KotlinPackage;
@@ -80,30 +79,9 @@ public class JetSourceNavigationHelper {
@Nullable
public static JetClassOrObject getSourceClassOrObject(@NotNull JetClassOrObject decompiledClassOrObject) {
if (decompiledClassOrObject instanceof JetObjectDeclaration && decompiledClassOrObject.getParent() instanceof JetClassObject) {
return getSourceClassObject((JetClassObject) decompiledClassOrObject.getParent());
}
return getSourceForNamedClassOrObject(decompiledClassOrObject);
}
private static JetClassOrObject getSourceClassObject(JetClassObject decompiledClassObject) {
JetClass decompiledClass = PsiTreeUtil.getParentOfType(decompiledClassObject, JetClass.class);
assert decompiledClass != null;
JetClass sourceClass = (JetClass) getSourceForNamedClassOrObject(decompiledClass);
if (sourceClass == null) {
return null;
}
if (sourceClass.hasModifier(JetTokens.ENUM_KEYWORD)) {
return sourceClass;
}
JetClassObject classObject = sourceClass.getClassObject();
assert classObject != null;
return classObject.getObjectDeclaration();
}
@NotNull
private static GlobalSearchScope createLibrarySourcesScope(@NotNull JetNamedDeclaration decompiledDeclaration) {
JetFile containingFile = decompiledDeclaration.getContainingJetFile();
@@ -458,11 +436,6 @@ public class JetSourceNavigationHelper {
return getSourceClassOrObject(declaration);
}
@Override
public JetDeclaration visitClassObject(@NotNull JetClassObject classObject, Void data) {
return getSourceClassObject(classObject);
}
@Override
public JetDeclaration visitClass(@NotNull JetClass klass, Void data) {
return getSourceClassOrObject(klass);
@@ -31,7 +31,6 @@ import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.psi.JetDelegationSpecifierList
import org.jetbrains.kotlin.psi.JetDelegatorToSuperClass
import org.jetbrains.kotlin.lexer.JetTokens
import org.jetbrains.kotlin.psi.JetClassObject
import org.jetbrains.kotlin.serialization.deserialization.ProtoContainer
import org.jetbrains.kotlin.psi.stubs.impl.KotlinModifierListStubImpl
import org.jetbrains.kotlin.lexer.JetModifierKeywordToken
@@ -80,20 +79,10 @@ private class ClassClsStubBuilder(
}
private fun createClassOrObjectStubAndModifierListStub(): StubElement<out PsiElement> {
val isClassObject = classKind == ProtoBuf.Class.Kind.CLASS_OBJECT
if (isClassObject) {
val classObjectStub = KotlinPlaceHolderStubImpl<JetClassObject>(parentStub, JetStubElementTypes.CLASS_OBJECT)
val modifierList = createModifierListForClass(classObjectStub)
val objectDeclarationStub = doCreateClassOrObjectStub(classObjectStub)
createAnnotationStubs(c.components.annotationLoader.loadClassAnnotations(classProto, c.nameResolver), modifierList)
return objectDeclarationStub
}
else {
val classOrObjectStub = doCreateClassOrObjectStub(parentStub)
val modifierList = createModifierListForClass(classOrObjectStub)
createAnnotationStubs(c.components.annotationLoader.loadClassAnnotations(classProto, c.nameResolver), modifierList)
return classOrObjectStub
}
val classOrObjectStub = doCreateClassOrObjectStub()
val modifierList = createModifierListForClass(classOrObjectStub)
createAnnotationStubs(c.components.annotationLoader.loadClassAnnotations(classProto, c.nameResolver), modifierList)
return classOrObjectStub
}
private fun createModifierListForClass(parent: StubElement<out PsiElement>): KotlinModifierListStubImpl {
@@ -110,7 +99,7 @@ private class ClassClsStubBuilder(
return createModifierListStubForDeclaration(parent, classProto.getFlags(), relevantFlags, additionalModifiers)
}
private fun doCreateClassOrObjectStub(parent: StubElement<out PsiElement>): StubElement<out PsiElement> {
private fun doCreateClassOrObjectStub(): StubElement<out PsiElement> {
val isClassObject = classKind == ProtoBuf.Class.Kind.CLASS_OBJECT
val fqName = outerContext.memberFqNameProvider.getMemberFqName(classId.getRelativeClassName().shortName())
val shortName = fqName.shortName()?.ref()
@@ -121,7 +110,7 @@ private class ClassClsStubBuilder(
return when (classKind) {
ProtoBuf.Class.Kind.OBJECT, ProtoBuf.Class.Kind.CLASS_OBJECT -> {
KotlinObjectStubImpl(
parent, shortName, fqName, superTypeRefs,
parentStub, shortName, fqName, superTypeRefs,
isTopLevel = classId.isTopLevelClass(),
isClassObject = isClassObject,
isLocal = false,
@@ -131,7 +120,7 @@ private class ClassClsStubBuilder(
else -> {
KotlinClassStubImpl(
JetClassElementType.getStubType(classKind == ProtoBuf.Class.Kind.ENUM_ENTRY),
parent,
parentStub,
fqName.ref(),
shortName,
superTypeRefs,
@@ -85,9 +85,6 @@ private object DeclarationKindDetector : JetVisitor<AnnotationHostKind?, Unit?>(
override fun visitClass(d: JetClass, _: Unit?) = detect(d, if (d.isTrait()) "trait" else "class")
override fun visitClassObject(d: JetClassObject, _: Unit?) = detect(d, "class object",
name = "of " + d.getStrictParentOfType<JetClass>()?.getName())
override fun visitNamedFunction(d: JetNamedFunction, _: Unit?) = detect(d, "fun")
override fun visitProperty(d: JetProperty, _: Unit?) = detect(d, d.getValOrVarNode().getText()!!)
@@ -102,7 +99,7 @@ private object DeclarationKindDetector : JetVisitor<AnnotationHostKind?, Unit?>(
override fun visitParameter(d: JetParameter, _: Unit?) = detect(d, "parameter", newLineNeeded = false)
override fun visitObjectDeclaration(d: JetObjectDeclaration, _: Unit?): AnnotationHostKind? {
if (d.getParent() is JetClassObject) return null
if (d.isClassObject()) return detect(d, "class object", name = "${d.getName()} of ${d.getStrictParentOfType<JetClass>()?.getName()}")
if (d.getParent() is JetObjectLiteralExpression) return null
return detect(d, "object")
}
@@ -166,10 +166,6 @@ public class JetStructureViewElement implements StructureViewTreeElement, Querya
else if (element instanceof JetClassOrObject) {
return ((JetClassOrObject) element).getDeclarations();
}
else if (element instanceof JetClassObject) {
JetObjectDeclaration objectDeclaration = ((JetClassObject) element).getObjectDeclaration();
return objectDeclaration.getDeclarations();
}
return Collections.emptyList();
}
@@ -60,8 +60,10 @@ public class JetDeclarationMover extends AbstractJetUpDownMover {
}
@Override
public void visitClassObject(@NotNull JetClassObject classObject) {
memberSuspects.add(classObject.getClassKeyword());
public void visitObjectDeclaration(@NotNull JetObjectDeclaration declaration) {
if (declaration.isClassObject()) {
memberSuspects.add(declaration.getClassKeyword());
}
}
@Override
@@ -193,9 +193,6 @@ private fun addDebugExpressionBeforeContextElement(codeFragment: JetCodeFragment
contextElement is JetClassOrObject -> {
insertNewInitializer(contextElement.getBody())
}
contextElement is JetClassObject -> {
insertNewInitializer(contextElement.getObjectDeclaration().getBody())
}
contextElement is JetFunctionLiteral -> {
val block = contextElement.getBodyExpression()!!
block.getStatements().firstOrNull() ?: block.getLastChild()
@@ -1,66 +0,0 @@
/*
* Copyright 2010-2015 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.kotlin.idea.projectView;
import com.intellij.ide.projectView.PresentationData;
import com.intellij.ide.projectView.ViewSettings;
import com.intellij.ide.projectView.impl.nodes.AbstractPsiBasedNode;
import com.intellij.ide.util.treeView.AbstractTreeNode;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import org.jetbrains.kotlin.psi.JetClassObject;
import org.jetbrains.kotlin.psi.JetPsiUtil;
import java.util.Collection;
import static org.jetbrains.kotlin.idea.projectView.JetProjectViewUtil.canRepresentPsiElement;
import static org.jetbrains.kotlin.idea.projectView.JetProjectViewUtil.getClassOrObjectChildren;
public class JetClassObjectTreeNode extends AbstractPsiBasedNode<JetClassObject> {
protected JetClassObjectTreeNode(Project project, JetClassObject classObject, ViewSettings viewSettings) {
super(project, classObject, viewSettings);
}
@Override
protected PsiElement extractPsiFromValue() {
return getValue();
}
@Override
protected Collection<AbstractTreeNode> getChildrenImpl() {
return getClassOrObjectChildren(getValue().getObjectDeclaration(), getProject(), getSettings());
}
@Override
protected void updateImpl(PresentationData data) {
data.setPresentableText("<class object>");
}
@Override
public boolean canRepresent(Object element) {
if (!isValid()) {
return false;
}
return super.canRepresent(element) || canRepresentPsiElement(getValue(), element, getSettings());
}
@Override
protected boolean isDeprecated() {
return JetPsiUtil.isDeprecated(getValue());
}
}
@@ -21,7 +21,6 @@ import com.intellij.ide.util.treeView.AbstractTreeNode;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.kotlin.psi.JetClassObject;
import org.jetbrains.kotlin.psi.JetClassOrObject;
import org.jetbrains.kotlin.psi.JetDeclaration;
@@ -44,9 +43,6 @@ public final class JetProjectViewUtil {
if (declaration instanceof JetClassOrObject) {
result.add(new JetClassOrObjectTreeNode(project, (JetClassOrObject) declaration, settings));
}
else if (declaration instanceof JetClassObject) {
result.add(new JetClassObjectTreeNode(project, (JetClassObject) declaration, settings));
}
else {
result.add(new JetDeclarationTreeNode(project, declaration, settings));
}
@@ -117,8 +117,7 @@ public class JetRunConfigurationProducer extends RuntimeConfigurationProducer im
currentElement = PsiTreeUtil.getParentOfType((PsiElement) currentElement, JetClassOrObject.class, JetFile.class)) {
JetDeclarationContainer entryPointContainer = currentElement;
if (entryPointContainer instanceof JetClass) {
JetClassObject classObject = ((JetClass) currentElement).getClassObject();
entryPointContainer = classObject != null ? classObject.getObjectDeclaration() : null;
entryPointContainer = ((JetClass) currentElement).getClassObject();
}
if (entryPointContainer != null && mainFunctionDetector.hasMain(entryPointContainer.getDeclarations())) return entryPointContainer;
}
@@ -72,7 +72,6 @@ import org.jetbrains.kotlin.psi.JetParameter
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.psi.JetClassOrObject
import org.jetbrains.kotlin.psi.JetCallableDeclaration
import org.jetbrains.kotlin.psi.JetClassObject
import org.jetbrains.kotlin.psi.JetTypeParameter
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.renderer.DescriptorRenderer
@@ -695,9 +694,6 @@ public class JetPsiUnifier(
e1 is JetMultiDeclaration && e2 is JetMultiDeclaration ->
if (matchMultiDeclarations(e1, e2)) null else UNMATCHED
e1 is JetClassObject && e2 is JetClassObject ->
e1.getObjectDeclaration().matchDeclarations(e2.getObjectDeclaration())
e1 is JetClassInitializer && e2 is JetClassInitializer ->
null
@@ -1,4 +1,4 @@
// "Suppress 'REDUNDANT_NULLABLE' for class object of C" "true"
// "Suppress 'REDUNDANT_NULLABLE' for class object Default of C" "true"
class C {
[suppress("REDUNDANT_NULLABLE")]
@@ -1,4 +1,4 @@
// "Suppress 'REDUNDANT_NULLABLE' for class object of C" "true"
// "Suppress 'REDUNDANT_NULLABLE' for class object Default of C" "true"
class C {
class object {
@@ -37,7 +37,6 @@ import org.jetbrains.kotlin.psi.stubs.KotlinPropertyStub
import kotlin.test.assertEquals
import org.jetbrains.kotlin.psi.JetClassBody
import org.jetbrains.kotlin.psi.JetClassInitializer
import org.jetbrains.kotlin.psi.JetClassObject
import org.jetbrains.kotlin.psi.debugText.getDebugText
public class DebugTextByStubTest : LightCodeInsightFixtureTestCase() {
@@ -201,10 +200,10 @@ public class DebugTextByStubTest : LightCodeInsightFixtureTestCase() {
}
fun testClassObject() {
val tree = createStubTree("class A { class object {} }")
val tree = createStubTree("class A { class object Def {} }")
val classObject = tree.findChildStubByType(JetStubElementTypes.CLASS)!!.findChildStubByType(JetStubElementTypes.CLASS_BODY)!!
.findChildStubByType(JetStubElementTypes.CLASS_OBJECT)
assertEquals("class object in STUB: class A", JetClassObject(classObject as KotlinPlaceHolderStub).getDebugText())
.findChildStubByType(JetStubElementTypes.OBJECT_DECLARATION)
assertEquals("STUB: class object Def", JetObjectDeclaration(classObject as KotlinObjectStub).getDebugText())
}
fun testPropertyAccessors() {