diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassBodyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassBodyCodegen.java index fcc1c540482..1fd5dec89b7 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassBodyCodegen.java @@ -99,9 +99,6 @@ public abstract class ClassBodyCodegen extends MemberCodegen { genClassOrObject((JetClassOrObject) declaration); } - else if (declaration instanceof JetClassObject) { - genClassOrObject(((JetClassObject) declaration).getObjectDeclaration()); - } } private void generatePrimaryConstructorProperties(PropertyCodegen propertyCodegen, JetClassOrObject origin) { diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java index 6b89164c566..3a11a2f98a8 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java @@ -150,7 +150,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { isStatic = !jetClass.isInner(); } else { - isStatic = myClass.getParent() instanceof JetClassObject; + isStatic = myClass instanceof JetObjectDeclaration && ((JetObjectDeclaration) myClass).isClassObject() ; isFinal = true; } @@ -968,9 +968,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { fieldTypeDescriptor = descriptor; } else if (classObjectDescriptor != null) { - JetClassObject classObject = ((JetClass) myClass).getClassObject(); + JetObjectDeclaration classObject = ((JetClass) myClass).getClassObject(); assert classObject != null : "Class object not found: " + myClass.getText(); - original = classObject.getObjectDeclaration(); + original = classObject; fieldTypeDescriptor = classObjectDescriptor; } else { diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/binding/CodegenAnnotatingVisitor.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/binding/CodegenAnnotatingVisitor.java index e6a744a51d7..4f0990a4c57 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/binding/CodegenAnnotatingVisitor.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/binding/CodegenAnnotatingVisitor.java @@ -207,46 +207,23 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid { } @Override - public void visitClassObject(@NotNull JetClassObject classObject) { - ClassDescriptor classDescriptor = bindingContext.get(CLASS, classObject.getObjectDeclaration()); + public void visitObjectDeclaration(@NotNull JetObjectDeclaration declaration) { + if (!filter.shouldProcessClass(declaration)) return; - assert classDescriptor != null : String.format("No class found in binding context for: \n---\n%s\n---\n", - JetPsiUtil.getElementTextWithContext(classObject)); + ClassDescriptor classDescriptor = bindingContext.get(CLASS, declaration); + // working around a problem with shallow analysis + if (classDescriptor == null) return; - //TODO_R: remove visitClassObject String name = getName(classDescriptor); recordClosure(classDescriptor, name); classStack.push(classDescriptor); nameStack.push(name); - super.visitClassObject(classObject); + super.visitObjectDeclaration(declaration); nameStack.pop(); classStack.pop(); } - @Override - public void visitObjectDeclaration(@NotNull JetObjectDeclaration declaration) { - if (declaration.getParent() instanceof JetClassObject) { - super.visitObjectDeclaration(declaration); - } - else { - if (!filter.shouldProcessClass(declaration)) return; - - ClassDescriptor classDescriptor = bindingContext.get(CLASS, declaration); - // working around a problem with shallow analysis - if (classDescriptor == null) return; - - String name = getName(classDescriptor); - recordClosure(classDescriptor, name); - - classStack.push(classDescriptor); - nameStack.push(name); - super.visitObjectDeclaration(declaration); - nameStack.pop(); - classStack.pop(); - } - } - @Override public void visitClass(@NotNull JetClass klass) { if (!filter.shouldProcessClass(klass)) return; diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/binding/PsiCodegenPredictor.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/binding/PsiCodegenPredictor.java index e06ac2f4360..de0267dcbb4 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/binding/PsiCodegenPredictor.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/binding/PsiCodegenPredictor.java @@ -55,10 +55,6 @@ public final class PsiCodegenPredictor { // TODO: Method won't give correct class name for traits implementations JetDeclaration parentDeclaration = JetStubbedPsiUtil.getContainingDeclaration(declaration); - if (parentDeclaration instanceof JetClassObject) { - assert declaration instanceof JetObjectDeclaration : "Only object declarations can be children of JetClassObject: " + declaration; - return getPredefinedJvmInternalName(parentDeclaration); - } String parentInternalName; if (parentDeclaration != null) { @@ -78,12 +74,6 @@ public final class PsiCodegenPredictor { parentInternalName = AsmUtil.internalNameByFqNameWithoutInnerClasses(containingFile.getPackageFqName()); } - if (declaration instanceof JetClassObject) { - // Get parent and assign Class object prefix - //TODO_R: getName() nullable - return parentInternalName + "$" + ((JetClassObject) declaration).getObjectDeclaration().getName(); - } - if (!PsiTreeUtil.instanceOf(declaration, JetClass.class, JetObjectDeclaration.class, JetNamedFunction.class, JetProperty.class) || declaration instanceof JetEnumEntry) { // Other subclasses are not valid for class name prediction. diff --git a/compiler/frontend/src/org/jetbrains/kotlin/JetNodeTypes.java b/compiler/frontend/src/org/jetbrains/kotlin/JetNodeTypes.java index 7f730d0288f..3dc47f9843b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/JetNodeTypes.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/JetNodeTypes.java @@ -35,7 +35,6 @@ public interface JetNodeTypes { IElementType OBJECT_DECLARATION = JetStubElementTypes.OBJECT_DECLARATION; JetNodeType OBJECT_DECLARATION_NAME = new JetNodeType("OBJECT_DECLARATION_NAME", JetObjectDeclarationName.class); - IElementType CLASS_OBJECT = JetStubElementTypes.CLASS_OBJECT; IElementType ENUM_ENTRY = JetStubElementTypes.ENUM_ENTRY; IElementType ANONYMOUS_INITIALIZER = JetStubElementTypes.ANONYMOUS_INITIALIZER; diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 5ddce51d76c..b709ac255dd 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -187,8 +187,8 @@ public interface Errors { // Class objects - DiagnosticFactory0 MANY_CLASS_OBJECTS = DiagnosticFactory0.create(ERROR); - DiagnosticFactory0 CLASS_OBJECT_NOT_ALLOWED = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 MANY_CLASS_OBJECTS = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 CLASS_OBJECT_NOT_ALLOWED = DiagnosticFactory0.create(ERROR); // Objects diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt index 9d5ed884af2..6e7aedb33e7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt @@ -51,10 +51,11 @@ public object PositioningStrategies { } return markRange(objectKeyword, delegationSpecifierList) } - is JetClassObject -> { - val classKeyword = element.getClassKeyword() - val objectKeyword = element.getObjectDeclaration().getObjectKeyword() - return markRange(classKeyword, objectKeyword) + is JetObjectDeclaration -> { + return markRange( + element.getClassKeyword() ?: element.getObjectKeyword(), + element.getNameIdentifier() ?: element.getObjectKeyword() + ) } else -> { return super.mark(element) @@ -99,17 +100,7 @@ public object PositioningStrategies { } return markElement(nameIdentifier) } - if (element is JetObjectDeclaration) { - val objectKeyword = element.getObjectKeyword() - val parent = element.getParent() - if (parent is JetClassObject) { - val classKeyword = parent.getClassKeyword() - val start = classKeyword ?: objectKeyword - return markRange(start, objectKeyword) - } - return markElement(objectKeyword) - } - return super.mark(element) + return DEFAULT.mark(element) } } @@ -240,7 +231,6 @@ public object PositioningStrategies { is JetObjectDeclaration -> element.getObjectKeyword() is JetPropertyAccessor -> element.getNamePlaceholder() is JetClassInitializer -> element - is JetClassObject -> element.getObjectDeclaration().getObjectKeyword() else -> throw IllegalArgumentException( "Can't find text range for element '${element.javaClass.getCanonicalName()}' with the text '${element.getText()}'") } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/DebugTextUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/DebugTextUtil.kt index 7048fec93d6..41d76c6ac57 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/DebugTextUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/DebugTextUtil.kt @@ -188,11 +188,6 @@ private object DebugTextBuildingVisitor : JetVisitor() { return "initializer in " + (containingDeclaration?.getDebugText() ?: "...") } - override fun visitClassObject(classObject: JetClassObject, data: Unit?): String? { - val containingDeclaration = JetStubbedPsiUtil.getContainingDeclaration(classObject) - return "class object in " + (containingDeclaration?.getDebugText() ?: "...") - } - override fun visitClassBody(classBody: JetClassBody, data: Unit?): String? { val containingDeclaration = JetStubbedPsiUtil.getContainingDeclaration(classBody) return "class body for " + (containingDeclaration?.getDebugText() ?: "...") @@ -242,6 +237,9 @@ private object DebugTextBuildingVisitor : JetVisitor() { return buildText { append("STUB: ") appendInn(declaration.getModifierList(), suffix = " ") + if (declaration.isClassObject()) { + append("class ") + } append("object ") appendInn(declaration.getNameAsName()) appendInn(declaration.getDelegationSpecifierList(), prefix = " : ") diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClass.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClass.java index b20663c7f4a..f39b07909eb 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClass.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClass.java @@ -142,7 +142,7 @@ public class JetClass extends JetTypeParameterListOwnerStub imp } @Nullable - public JetClassObject getClassObject() { + public JetObjectDeclaration getClassObject() { JetClassBody body = getBody(); if (body == null) return null; return body.getClassObject(); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClassBody.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClassBody.java index 759a165ce24..07f8a0767c6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClassBody.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClassBody.java @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.psi; +import com.google.common.collect.Lists; import com.intellij.lang.ASTNode; import com.intellij.psi.PsiElement; import com.intellij.psi.tree.TokenSet; @@ -31,6 +32,7 @@ import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes; import java.util.Arrays; import java.util.List; +import static kotlin.KotlinPackage.firstOrNull; import static org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes.*; public class JetClassBody extends JetElementImplStub> implements JetDeclarationContainer { @@ -65,13 +67,19 @@ public class JetClassBody extends JetElementImplStub getAllClassObjects() { - return getStubOrPsiChildrenAsList(JetStubElementTypes.CLASS_OBJECT); + public List getAllClassObjects() { + List result = Lists.newArrayList(); + for (JetObjectDeclaration declaration : getStubOrPsiChildrenAsList(JetStubElementTypes.OBJECT_DECLARATION)) { + if (declaration.isClassObject()) { + result.add(declaration); + } + } + return result; } @Nullable diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClassObject.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClassObject.java deleted file mode 100644 index 3156e5f8c70..00000000000 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClassObject.java +++ /dev/null @@ -1,49 +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.psi; - -import com.intellij.lang.ASTNode; -import com.intellij.psi.PsiElement; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.lexer.JetTokens; -import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub; -import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes; - -public class JetClassObject extends JetDeclarationStub> implements JetStatementExpression { - public JetClassObject(@NotNull ASTNode node) { - super(node); - } - - public JetClassObject(@NotNull KotlinPlaceHolderStub stub) { - super(stub, JetStubElementTypes.CLASS_OBJECT); - } - - @Override - public R accept(@NotNull JetVisitor visitor, D data) { - return visitor.visitClassObject(this, data); - } - - @NotNull - public JetObjectDeclaration getObjectDeclaration() { - return getRequiredStubOrPsiChild(JetStubElementTypes.OBJECT_DECLARATION); - } - - @NotNull - public PsiElement getClassKeyword() { - return findChildByType(JetTokens.CLASS_KEYWORD); - } -} diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetNamedDeclarationUtil.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetNamedDeclarationUtil.java index cdc4e726f06..afa4d338a2f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetNamedDeclarationUtil.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetNamedDeclarationUtil.java @@ -51,9 +51,6 @@ public final class JetNamedDeclarationUtil { @Nullable public static FqName getParentFqName(@NotNull JetNamedDeclaration namedDeclaration) { PsiElement parent = namedDeclaration.getParent(); - if (parent instanceof JetClassObject) { - parent = parent.getParent(); - } if (parent instanceof JetClassBody) { // One nesting to JetClassBody doesn't affect to qualified name parent = parent.getParent(); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiFactory.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiFactory.kt index 618d439861e..27472481142 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiFactory.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiFactory.kt @@ -645,10 +645,6 @@ public class JetPsiFactory(private val project: Project) { return createFunction("fun foo() {\n" + bodyText + "\n}").getBodyExpression() as JetBlockExpression } - public fun createEmptyClassObject(): JetClassObject { - return createClass("class foo { class object { } }").getClassObject()!! - } - public fun createComment(text: String): PsiComment { val file = createFile(text) val comments = file.getChildren().filterIsInstance() diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiUtil.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiUtil.java index 24af2ab33c7..85deec99892 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiUtil.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiUtil.java @@ -431,11 +431,6 @@ public class JetPsiUtil { if (parent instanceof PsiFile) { return current; } - if (parent instanceof JetClassObject) { - // current class IS the class object declaration - parent = parent.getParent(); - assert parent instanceof JetClassBody : "Parent of class object is not a class body: " + parent; - } if (!(parent instanceof JetClassBody)) { // It is a local class, no legitimate outer return current; diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetVisitor.java index 9d387a55a36..79cf79de17d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetVisitor.java @@ -33,10 +33,6 @@ public class JetVisitor extends PsiElementVisitor { return visitNamedDeclaration(klass, data); } - public R visitClassObject(@NotNull JetClassObject classObject, D data) { - return visitDeclaration(classObject, data); - } - public R visitNamedFunction(@NotNull JetNamedFunction function, D data) { return visitNamedDeclaration(function, data); } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetVisitorVoid.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetVisitorVoid.java index 5a31d91f91c..289cfd2370d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetVisitorVoid.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetVisitorVoid.java @@ -33,10 +33,6 @@ public class JetVisitorVoid extends JetVisitor { super.visitClass(klass, null); } - public void visitClassObject(@NotNull JetClassObject classObject) { - super.visitClassObject(classObject, null); - } - public void visitNamedFunction(@NotNull JetNamedFunction function) { super.visitNamedFunction(function, null); } @@ -436,12 +432,6 @@ public class JetVisitorVoid extends JetVisitor { return null; } - @Override - public final Void visitClassObject(@NotNull JetClassObject classObject, Void data) { - visitClassObject(classObject); - return null; - } - @Override public final Void visitNamedFunction(@NotNull JetNamedFunction function, Void data) { visitNamedFunction(function); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetVisitorVoidWithParameter.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetVisitorVoidWithParameter.java index 4011f0a8fdc..bc086241de6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetVisitorVoidWithParameter.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetVisitorVoidWithParameter.java @@ -34,10 +34,6 @@ public class JetVisitorVoidWithParameter

extends JetVisitor { super.visitClass(klass, data); } - public void visitClassObjectVoid(@NotNull JetClassObject classObject, P data) { - super.visitClassObject(classObject, data); - } - public void visitNamedFunctionVoid(@NotNull JetNamedFunction function, P data) { super.visitNamedFunction(function, data); } @@ -433,12 +429,6 @@ public class JetVisitorVoidWithParameter

extends JetVisitor { return null; } - @Override - public final Void visitClassObject(@NotNull JetClassObject classObject, P data) { - visitClassObjectVoid(classObject, data); - return null; - } - @Override public final Void visitNamedFunction(@NotNull JetNamedFunction function, P data) { visitNamedFunctionVoid(function, data); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/JetObjectElementType.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/JetObjectElementType.java index 144f5499baa..82cd27d33a4 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/JetObjectElementType.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/JetObjectElementType.java @@ -24,7 +24,6 @@ import com.intellij.util.io.StringRef; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.name.FqName; -import org.jetbrains.kotlin.psi.JetClassObject; import org.jetbrains.kotlin.psi.JetObjectDeclaration; import org.jetbrains.kotlin.psi.psiUtil.PsiUtilPackage; import org.jetbrains.kotlin.psi.stubs.KotlinObjectStub; @@ -46,7 +45,7 @@ public class JetObjectElementType extends JetStubElementType superNames = PsiUtilPackage.getSuperNames(psi); return new KotlinObjectStubImpl(parentStub, StringRef.fromString(name), fqName, Utils.INSTANCE$.wrapStrings(superNames), - psi.isTopLevel(), isClassObject(psi), psi.isLocal(), psi.isObjectLiteral()); + psi.isTopLevel(), psi.isClassObject(), psi.isLocal(), psi.isObjectLiteral()); } @Override @@ -93,8 +92,4 @@ public class JetObjectElementType extends JetStubElementType CLASS_OBJECT = - new JetPlaceHolderStubElementType("CLASS_OBJECT", JetClassObject.class); JetPlaceHolderStubElementType ANONYMOUS_INITIALIZER = new JetPlaceHolderStubElementType("ANONYMOUS_INITIALIZER", JetClassInitializer.class); @@ -115,7 +113,7 @@ public interface JetStubElementTypes { new JetPlaceHolderStubElementType("CONSTRUCTOR_CALLEE", JetConstructorCalleeExpression.class); TokenSet DECLARATION_TYPES = - TokenSet.create(CLASS, OBJECT_DECLARATION, CLASS_OBJECT, FUNCTION, PROPERTY, ANONYMOUS_INITIALIZER, ENUM_ENTRY); + TokenSet.create(CLASS, OBJECT_DECLARATION, FUNCTION, PROPERTY, ANONYMOUS_INITIALIZER, ENUM_ENTRY); TokenSet DELEGATION_SPECIFIER_TYPES = TokenSet.create(DELEGATOR_BY, DELEGATOR_SUPER_CALL, DELEGATOR_SUPER_CLASS, THIS_CALL); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/LazyTopDownAnalyzer.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/LazyTopDownAnalyzer.java index 174de2faaa9..693f2922819 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/LazyTopDownAnalyzer.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/LazyTopDownAnalyzer.java @@ -199,9 +199,9 @@ public class LazyTopDownAnalyzer { for (JetDeclaration jetDeclaration : classOrObject.getDeclarations()) { jetDeclaration.accept(this); - if (jetDeclaration instanceof JetClassObject) { + if (jetDeclaration instanceof JetObjectDeclaration && ((JetObjectDeclaration) jetDeclaration).isClassObject()) { if (classObjectAlreadyFound) { - trace.report(MANY_CLASS_OBJECTS.on((JetClassObject) jetDeclaration)); + trace.report(MANY_CLASS_OBJECTS.on((JetObjectDeclaration) jetDeclaration)); } classObjectAlreadyFound = true; } @@ -226,11 +226,6 @@ public class LazyTopDownAnalyzer { } } - @Override - public void visitClassObject(@NotNull JetClassObject classObject) { - visitClassOrObject(classObject.getObjectDeclaration()); - } - @Override public void visitEnumEntry(@NotNull JetEnumEntry enumEntry) { visitClassOrObject(enumEntry); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.java index c696b2d3779..abc640b8fa1 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.java @@ -171,7 +171,7 @@ public class ModifiersChecker { checkCompatibility(modifierList, Arrays.asList(ABSTRACT_KEYWORD, OPEN_KEYWORD, FINAL_KEYWORD), Arrays.asList(ABSTRACT_KEYWORD, OPEN_KEYWORD)); - if (modifierListOwner.getParent() instanceof JetClassObject || modifierListOwner instanceof JetObjectDeclaration) { + if (modifierListOwner instanceof JetObjectDeclaration) { checkIllegalModalityModifiers(modifierListOwner); } else if (modifierListOwner instanceof JetClassOrObject) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/DeclarationScopeProviderImpl.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/DeclarationScopeProviderImpl.java index abe23c03598..ae18ed7ded8 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/DeclarationScopeProviderImpl.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/DeclarationScopeProviderImpl.java @@ -68,16 +68,6 @@ public class DeclarationScopeProviderImpl implements DeclarationScopeProvider { return classDescriptor.getScopeForMemberDeclarationResolution(); } - if (parentDeclaration instanceof JetClassObject) { - assert jetDeclaration instanceof JetObjectDeclaration : "Should be situation for getting scope for object in class [object {...}]"; - - JetClassObject classObject = (JetClassObject) parentDeclaration; - LazyClassDescriptor classObjectDescriptor = - (LazyClassDescriptor) lazyDeclarationResolver.getClassObjectDescriptor(classObject).getContainingDeclaration(); - - return classObjectDescriptor.getScopeForMemberDeclarationResolution(); - } - throw new IllegalStateException("Don't call this method for local declarations: " + jetDeclaration + "\n" + JetPsiUtil.getElementTextWithContext(jetDeclaration)); } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyDeclarationResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyDeclarationResolver.java index c35a346e0cf..ea126f9accc 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyDeclarationResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyDeclarationResolver.java @@ -27,7 +27,6 @@ import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.renderer.DescriptorRenderer; import org.jetbrains.kotlin.resolve.BindingContext; import org.jetbrains.kotlin.resolve.BindingTrace; -import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor; import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyPackageDescriptor; import org.jetbrains.kotlin.resolve.scopes.JetScope; import org.jetbrains.kotlin.storage.LockBasedLazyResolveStorageManager; @@ -65,13 +64,6 @@ public class LazyDeclarationResolver { @NotNull public ClassDescriptor getClassDescriptor(@NotNull JetClassOrObject classOrObject) { - if (classOrObject instanceof JetObjectDeclaration) { - JetObjectDeclaration objectDeclaration = (JetObjectDeclaration) classOrObject; - JetClassObject classObjectElement = objectDeclaration.getClassObjectElement(); - if (classObjectElement != null) { - return getClassObjectDescriptor(classObjectElement); - } - } JetScope resolutionScope = resolutionScopeToResolveDeclaration(classOrObject); // Why not use the result here. Because it may be that there is a redeclaration: @@ -93,31 +85,6 @@ public class LazyDeclarationResolver { return (ClassDescriptor) descriptor; } - @NotNull - /*package*/ LazyClassDescriptor getClassObjectDescriptor(@NotNull JetClassObject classObject) { - JetClass aClass = JetStubbedPsiUtil.getContainingDeclaration(classObject, JetClass.class); - - LazyClassDescriptor parentClassDescriptor; - - if (aClass != null) { - parentClassDescriptor = (LazyClassDescriptor) getClassDescriptor(aClass); - } - else { - // Class object in object is an error but we want to find descriptors even for this case - JetObjectDeclaration objectDeclaration = PsiTreeUtil.getParentOfType(classObject, JetObjectDeclaration.class); - assert objectDeclaration != null : String.format("Class object %s can be in class or object in file %s", classObject, classObject.getContainingFile().getText()); - parentClassDescriptor = (LazyClassDescriptor) getClassDescriptor(objectDeclaration); - } - - // Activate resolution and writing to trace - parentClassDescriptor.getClassObjectDescriptor(); - parentClassDescriptor.getDescriptorsForExtraClassObjects(); - DeclarationDescriptor classObjectDescriptor = getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, classObject.getObjectDeclaration()); - assert classObjectDescriptor != null : "No descriptor found for " + JetPsiUtil.getElementTextWithContext(classObject); - - return (LazyClassDescriptor) classObjectDescriptor; - } - @NotNull private BindingContext getBindingContext() { return trace.getBindingContext(); @@ -133,19 +100,9 @@ public class LazyDeclarationResolver { @Override public DeclarationDescriptor visitObjectDeclaration(@NotNull JetObjectDeclaration declaration, Void data) { - PsiElement parent = declaration.getParent(); - if (parent instanceof JetClassObject) { - JetClassObject jetClassObject = (JetClassObject) parent; - return resolveToDescriptor(jetClassObject); - } return getClassDescriptor(declaration); } - @Override - public DeclarationDescriptor visitClassObject(@NotNull JetClassObject classObject, Void data) { - return getClassObjectDescriptor(classObject); - } - @Override public DeclarationDescriptor visitTypeParameter(@NotNull JetTypeParameter parameter, Void data) { JetTypeParameterListOwner ownerElement = PsiTreeUtil.getParentOfType(parameter, JetTypeParameterListOwner.class); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/data/JetClassInfo.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/data/JetClassInfo.java index bbbc86c5d65..a4028be5141 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/data/JetClassInfo.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/data/JetClassInfo.java @@ -46,7 +46,7 @@ public class JetClassInfo extends JetClassOrObjectInfo { } @Override - public JetClassObject getClassObject() { + public JetObjectDeclaration getClassObject() { return element.getClassObject(); } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/data/JetClassLikeInfo.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/data/JetClassLikeInfo.java index 71cc9d4d068..9c10c34b58d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/data/JetClassLikeInfo.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/data/JetClassLikeInfo.java @@ -21,8 +21,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.ReadOnly; import org.jetbrains.kotlin.descriptors.ClassKind; -import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.name.FqName; +import org.jetbrains.kotlin.psi.*; import java.util.List; @@ -34,11 +34,11 @@ public interface JetClassLikeInfo extends JetDeclarationContainer { JetModifierList getModifierList(); @Nullable - JetClassObject getClassObject(); + JetObjectDeclaration getClassObject(); @NotNull @ReadOnly - List getClassObjects(); + List getClassObjects(); // This element is used to identify resolution scope for the class @NotNull diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/data/JetClassOrObjectInfo.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/data/JetClassOrObjectInfo.java index 2001283c1c7..93e12041d6b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/data/JetClassOrObjectInfo.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/data/JetClassOrObjectInfo.java @@ -58,7 +58,7 @@ public abstract class JetClassOrObjectInfo implement @NotNull @Override - public List getClassObjects() { + public List getClassObjects() { JetClassBody body = element.getBody(); if (body == null) { return Collections.emptyList(); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/data/JetObjectInfo.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/data/JetObjectInfo.java index d68b8f57abe..60266d5046e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/data/JetObjectInfo.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/data/JetObjectInfo.java @@ -19,7 +19,6 @@ package org.jetbrains.kotlin.resolve.lazy.data; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.descriptors.ClassKind; -import org.jetbrains.kotlin.psi.JetClassObject; import org.jetbrains.kotlin.psi.JetObjectDeclaration; import org.jetbrains.kotlin.psi.JetParameter; import org.jetbrains.kotlin.psi.JetTypeParameterList; @@ -39,7 +38,7 @@ public class JetObjectInfo extends JetClassOrObjectInfo { } @Override - public JetClassObject getClassObject() { + public JetObjectDeclaration getClassObject() { return null; } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/data/JetScriptInfo.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/data/JetScriptInfo.kt index 96fa7ecad50..9e023b41655 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/data/JetScriptInfo.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/data/JetScriptInfo.kt @@ -28,7 +28,7 @@ public class JetScriptInfo( override fun getContainingPackageFqName() = fqName.parent() override fun getModifierList() = null override fun getClassObject() = null - override fun getClassObjects() = listOf() + override fun getClassObjects() = listOf() override fun getScopeAnchor() = script override fun getCorrespondingClassOrObject() = null override fun getTypeParameterList() = null @@ -44,5 +44,5 @@ public fun shouldBeScriptClassMember(declaration: JetDeclaration): Boolean { // we only add those vals, vars and funs that have explicitly specified return types // (or implicit Unit for function with block body) return declaration is JetCallableDeclaration && declaration.getTypeReference() != null - || declaration is JetNamedFunction && declaration.hasBlockBody() + || declaration is JetNamedFunction && declaration.hasBlockBody() } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/declarations/PsiBasedClassMemberDeclarationProvider.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/declarations/PsiBasedClassMemberDeclarationProvider.kt index e8caeb83672..ad22909fc45 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/declarations/PsiBasedClassMemberDeclarationProvider.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/declarations/PsiBasedClassMemberDeclarationProvider.kt @@ -29,12 +29,7 @@ public class PsiBasedClassMemberDeclarationProvider( override fun doCreateIndex(index: AbstractPsiBasedDeclarationProvider.Index) { for (declaration in classInfo.getDeclarations()) { - if (declaration !is JetClassObject) { - index.putToIndex(declaration) - } - else { - index.putToIndex(declaration.getObjectDeclaration()) - } + index.putToIndex(declaration) } for (parameter in classInfo.getPrimaryConstructorParameters()) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassDescriptor.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassDescriptor.java index 6bb0ad2355c..81d02caf936 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassDescriptor.java @@ -83,7 +83,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes private final Annotations annotations; private final Annotations danglingAnnotations; private final NullableLazyValue classObjectDescriptor; - private final MemoizedFunctionToNotNull extraClassObjectDescriptors; + private final MemoizedFunctionToNotNull extraClassObjectDescriptors; private final LazyClassMemberScope unsubstitutedMemberScope; private final JetScope staticScope = new StaticScopeForKotlinClass(this); @@ -186,9 +186,9 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes return computeClassObjectDescriptor(getClassObjectIfAllowed()); } }); - this.extraClassObjectDescriptors = storageManager.createMemoizedFunction(new Function1() { + this.extraClassObjectDescriptors = storageManager.createMemoizedFunction(new Function1() { @Override - public ClassDescriptor invoke(JetClassObject classObject) { + public ClassDescriptor invoke(JetObjectDeclaration classObject) { return computeClassObjectDescriptor(classObject); } }); @@ -357,21 +357,21 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes @NotNull @ReadOnly public List getDescriptorsForExtraClassObjects() { - final JetClassObject allowedClassObject = getClassObjectIfAllowed(); + final JetObjectDeclaration allowedClassObject = getClassObjectIfAllowed(); return KotlinPackage.map( KotlinPackage.filter( declarationProvider.getOwnerInfo().getClassObjects(), - new Function1() { + new Function1() { @Override - public Boolean invoke(JetClassObject classObject) { + public Boolean invoke(JetObjectDeclaration classObject) { return classObject != allowedClassObject; } } ), - new Function1() { + new Function1() { @Override - public ClassDescriptor invoke(JetClassObject classObject) { + public ClassDescriptor invoke(JetObjectDeclaration classObject) { return extraClassObjectDescriptors.invoke(classObject); } } @@ -379,7 +379,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes } @Nullable - private LazyClassDescriptor computeClassObjectDescriptor(@Nullable JetClassObject classObject) { + private LazyClassDescriptor computeClassObjectDescriptor(@Nullable JetObjectDeclaration classObject) { JetClassLikeInfo classObjectInfo = getClassObjectInfo(classObject); if (classObjectInfo instanceof JetClassOrObjectInfo) { Name name = ((JetClassOrObjectInfo) classObjectInfo).getName(); @@ -404,21 +404,21 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes } @Nullable - private JetClassLikeInfo getClassObjectInfo(@Nullable JetClassObject classObject) { + private JetClassLikeInfo getClassObjectInfo(@Nullable JetObjectDeclaration classObject) { if (classObject != null) { if (!isClassObjectAllowed()) { c.getTrace().report(CLASS_OBJECT_NOT_ALLOWED.on(classObject)); } - return JetClassInfoUtil.createClassLikeInfo(classObject.getObjectDeclaration()); + return JetClassInfoUtil.createClassLikeInfo(classObject); } return null; } @Nullable - private JetClassObject getClassObjectIfAllowed() { - JetClassObject classObject = declarationProvider.getOwnerInfo().getClassObject(); + private JetObjectDeclaration getClassObjectIfAllowed() { + JetObjectDeclaration classObject = declarationProvider.getOwnerInfo().getClassObject(); return (classObject != null && isClassObjectAllowed()) ? classObject : null; } diff --git a/compiler/tests/org/jetbrains/kotlin/renderer/AbstractDescriptorRendererTest.kt b/compiler/tests/org/jetbrains/kotlin/renderer/AbstractDescriptorRendererTest.kt index 1d7ec94365c..c72a8efff2a 100644 --- a/compiler/tests/org/jetbrains/kotlin/renderer/AbstractDescriptorRendererTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/renderer/AbstractDescriptorRendererTest.kt @@ -71,10 +71,6 @@ public abstract class AbstractDescriptorRendererTest : KotlinTestWithEnvironment file.acceptChildren(this) } - override fun visitClassObject(classObject: JetClassObject) { - classObject.acceptChildren(this) - } - override fun visitParameter(parameter: JetParameter) { val declaringElement = parameter.getParent().getParent() when (declaringElement) { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/JetIconProvider.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/JetIconProvider.java index 34449055df6..fbc62878207 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/JetIconProvider.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/JetIconProvider.java @@ -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) { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/JetSourceNavigationHelper.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/JetSourceNavigationHelper.java index 954583cd8f1..9d085903b89 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/JetSourceNavigationHelper.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/JetSourceNavigationHelper.java @@ -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); diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClassClsStubBuilder.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClassClsStubBuilder.kt index 06cd4df8e9a..b60db677e84 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClassClsStubBuilder.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClassClsStubBuilder.kt @@ -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 { - val isClassObject = classKind == ProtoBuf.Class.Kind.CLASS_OBJECT - if (isClassObject) { - val classObjectStub = KotlinPlaceHolderStubImpl(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): KotlinModifierListStubImpl { @@ -110,7 +99,7 @@ private class ClassClsStubBuilder( return createModifierListStubForDeclaration(parent, classProto.getFlags(), relevantFlags, additionalModifiers) } - private fun doCreateClassOrObjectStub(parent: StubElement): StubElement { + private fun doCreateClassOrObjectStub(): StubElement { 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, diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinSuppressableWarningProblemGroup.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinSuppressableWarningProblemGroup.kt index 80c79f25a62..e0e6ea1cb9a 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinSuppressableWarningProblemGroup.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinSuppressableWarningProblemGroup.kt @@ -85,9 +85,6 @@ private object DeclarationKindDetector : JetVisitor( 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()?.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( 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()?.getName()}") if (d.getParent() is JetObjectLiteralExpression) return null return detect(d, "object") } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/structureView/JetStructureViewElement.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/structureView/JetStructureViewElement.java index 414faec45f5..7e9b74b066e 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/structureView/JetStructureViewElement.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/structureView/JetStructureViewElement.java @@ -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(); } diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/JetDeclarationMover.java b/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/JetDeclarationMover.java index 67eaaba3583..085902e24fc 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/JetDeclarationMover.java +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/upDownMover/JetDeclarationMover.java @@ -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 diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt index 8cfa6e61d15..be9de56bb58 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt @@ -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() diff --git a/idea/src/org/jetbrains/kotlin/idea/projectView/JetClassObjectTreeNode.java b/idea/src/org/jetbrains/kotlin/idea/projectView/JetClassObjectTreeNode.java deleted file mode 100644 index 3ac3c7db97d..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/projectView/JetClassObjectTreeNode.java +++ /dev/null @@ -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 { - protected JetClassObjectTreeNode(Project project, JetClassObject classObject, ViewSettings viewSettings) { - super(project, classObject, viewSettings); - } - - @Override - protected PsiElement extractPsiFromValue() { - return getValue(); - } - - @Override - protected Collection getChildrenImpl() { - return getClassOrObjectChildren(getValue().getObjectDeclaration(), getProject(), getSettings()); - } - - @Override - protected void updateImpl(PresentationData data) { - data.setPresentableText(""); - } - - @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()); - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/projectView/JetProjectViewUtil.java b/idea/src/org/jetbrains/kotlin/idea/projectView/JetProjectViewUtil.java index 38a44fd4ea4..e833fb60864 100644 --- a/idea/src/org/jetbrains/kotlin/idea/projectView/JetProjectViewUtil.java +++ b/idea/src/org/jetbrains/kotlin/idea/projectView/JetProjectViewUtil.java @@ -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)); } diff --git a/idea/src/org/jetbrains/kotlin/idea/run/JetRunConfigurationProducer.java b/idea/src/org/jetbrains/kotlin/idea/run/JetRunConfigurationProducer.java index 42a86aac9a3..ab151d894ca 100644 --- a/idea/src/org/jetbrains/kotlin/idea/run/JetRunConfigurationProducer.java +++ b/idea/src/org/jetbrains/kotlin/idea/run/JetRunConfigurationProducer.java @@ -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; } diff --git a/idea/src/org/jetbrains/kotlin/idea/util/psi/patternMatching/JetPsiUnifier.kt b/idea/src/org/jetbrains/kotlin/idea/util/psi/patternMatching/JetPsiUnifier.kt index 887662fa908..84e982162d3 100644 --- a/idea/src/org/jetbrains/kotlin/idea/util/psi/patternMatching/JetPsiUnifier.kt +++ b/idea/src/org/jetbrains/kotlin/idea/util/psi/patternMatching/JetPsiUnifier.kt @@ -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 diff --git a/idea/testData/quickfix/suppress/declarationKinds/afterClassObject.kt b/idea/testData/quickfix/suppress/declarationKinds/afterClassObject.kt index d6f897ae27f..593b6872e26 100644 --- a/idea/testData/quickfix/suppress/declarationKinds/afterClassObject.kt +++ b/idea/testData/quickfix/suppress/declarationKinds/afterClassObject.kt @@ -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")] diff --git a/idea/testData/quickfix/suppress/declarationKinds/beforeClassObject.kt b/idea/testData/quickfix/suppress/declarationKinds/beforeClassObject.kt index 92865aee6a8..c6b058626b9 100644 --- a/idea/testData/quickfix/suppress/declarationKinds/beforeClassObject.kt +++ b/idea/testData/quickfix/suppress/declarationKinds/beforeClassObject.kt @@ -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 { diff --git a/idea/tests/org/jetbrains/kotlin/idea/stubs/DebugTextByStubTest.kt b/idea/tests/org/jetbrains/kotlin/idea/stubs/DebugTextByStubTest.kt index 7fa69e4117f..7afc5a3bf98 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/stubs/DebugTextByStubTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/stubs/DebugTextByStubTest.kt @@ -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() { diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/declaration/DeclarationBodyVisitor.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/declaration/DeclarationBodyVisitor.java index f4dfd6a04e6..0ebad4b0d21 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/declaration/DeclarationBodyVisitor.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/declaration/DeclarationBodyVisitor.java @@ -84,8 +84,11 @@ public class DeclarationBodyVisitor extends TranslatorVisitor { } @Override - public Void visitClassObject(@NotNull JetClassObject classObject, TranslationContext context) { - JetObjectDeclaration declaration = classObject.getObjectDeclaration(); + public Void visitObjectDeclaration(@NotNull JetObjectDeclaration declaration, TranslationContext context) { + if (!declaration.isClassObject()) { + // parsed it in initializer visitor => no additional actions are needed + return null; + } JsExpression value = ClassTranslator.generateClassCreation(declaration, context); ClassDescriptor descriptor = getClassDescriptor(context.bindingContext(), declaration); @@ -94,12 +97,6 @@ public class DeclarationBodyVisitor extends TranslatorVisitor { return null; } - @Override - public Void visitObjectDeclaration(@NotNull JetObjectDeclaration declaration, TranslationContext context) { - // parsed it in initializer visitor => no additional actions are needed - return null; - } - @Override public Void visitNamedFunction(@NotNull JetNamedFunction expression, TranslationContext context) { FunctionDescriptor descriptor = getFunctionDescriptor(context.bindingContext(), expression); diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/initializer/InitializerVisitor.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/initializer/InitializerVisitor.java index 7ac2439807b..292ac2c0e99 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/initializer/InitializerVisitor.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/initializer/InitializerVisitor.java @@ -65,7 +65,9 @@ public final class InitializerVisitor extends TranslatorVisitor { @Override public Void visitObjectDeclaration(@NotNull JetObjectDeclaration declaration, @NotNull TranslationContext context) { - InitializerUtils.generateObjectInitializer(declaration, result, context); + if (!declaration.isClassObject()) { + InitializerUtils.generateObjectInitializer(declaration, result, context); + } return null; } }