Drop JetClassObject element and its usages
as class objects are now represented by JetObjectDeclaration element
This commit is contained in:
@@ -99,9 +99,6 @@ public abstract class ClassBodyCodegen extends MemberCodegen<JetClassOrObject> {
|
||||
|
||||
genClassOrObject((JetClassOrObject) declaration);
|
||||
}
|
||||
else if (declaration instanceof JetClassObject) {
|
||||
genClassOrObject(((JetClassObject) declaration).getObjectDeclaration());
|
||||
}
|
||||
}
|
||||
|
||||
private void generatePrimaryConstructorProperties(PropertyCodegen propertyCodegen, JetClassOrObject origin) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+6
-29
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -187,8 +187,8 @@ public interface Errors {
|
||||
|
||||
// Class objects
|
||||
|
||||
DiagnosticFactory0<JetClassObject> MANY_CLASS_OBJECTS = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<JetClassObject> CLASS_OBJECT_NOT_ALLOWED = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<JetObjectDeclaration> MANY_CLASS_OBJECTS = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<JetObjectDeclaration> CLASS_OBJECT_NOT_ALLOWED = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
// Objects
|
||||
|
||||
|
||||
@@ -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()}'")
|
||||
}
|
||||
|
||||
@@ -188,11 +188,6 @@ private object DebugTextBuildingVisitor : JetVisitor<String, Unit>() {
|
||||
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<String, Unit>() {
|
||||
return buildText {
|
||||
append("STUB: ")
|
||||
appendInn(declaration.getModifierList(), suffix = " ")
|
||||
if (declaration.isClassObject()) {
|
||||
append("class ")
|
||||
}
|
||||
append("object ")
|
||||
appendInn(declaration.getNameAsName())
|
||||
appendInn(declaration.getDelegationSpecifierList(), prefix = " : ")
|
||||
|
||||
@@ -142,7 +142,7 @@ public class JetClass extends JetTypeParameterListOwnerStub<KotlinClassStub> imp
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JetClassObject getClassObject() {
|
||||
public JetObjectDeclaration getClassObject() {
|
||||
JetClassBody body = getBody();
|
||||
if (body == null) return null;
|
||||
return body.getClassObject();
|
||||
|
||||
@@ -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<KotlinPlaceHolderStub<JetClassBody>> implements JetDeclarationContainer {
|
||||
@@ -65,13 +67,19 @@ public class JetClassBody extends JetElementImplStub<KotlinPlaceHolderStub<JetCl
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JetClassObject getClassObject() {
|
||||
return getStubOrPsiChild(CLASS_OBJECT);
|
||||
public JetObjectDeclaration getClassObject() {
|
||||
return firstOrNull(getAllClassObjects());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<JetClassObject> getAllClassObjects() {
|
||||
return getStubOrPsiChildrenAsList(JetStubElementTypes.CLASS_OBJECT);
|
||||
public List<JetObjectDeclaration> getAllClassObjects() {
|
||||
List<JetObjectDeclaration> result = Lists.newArrayList();
|
||||
for (JetObjectDeclaration declaration : getStubOrPsiChildrenAsList(JetStubElementTypes.OBJECT_DECLARATION)) {
|
||||
if (declaration.isClassObject()) {
|
||||
result.add(declaration);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -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<KotlinPlaceHolderStub<JetClassObject>> implements JetStatementExpression {
|
||||
public JetClassObject(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
public JetClassObject(@NotNull KotlinPlaceHolderStub<JetClassObject> stub) {
|
||||
super(stub, JetStubElementTypes.CLASS_OBJECT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(@NotNull JetVisitor<R, D> 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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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<PsiComment>()
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -33,10 +33,6 @@ public class JetVisitor<R, D> 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);
|
||||
}
|
||||
|
||||
@@ -33,10 +33,6 @@ public class JetVisitorVoid extends JetVisitor<Void, Void> {
|
||||
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<Void, Void> {
|
||||
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);
|
||||
|
||||
@@ -34,10 +34,6 @@ public class JetVisitorVoidWithParameter<P> extends JetVisitor<Void, P> {
|
||||
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<P> extends JetVisitor<Void, P> {
|
||||
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);
|
||||
|
||||
+1
-6
@@ -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<KotlinObjectStub, J
|
||||
FqName fqName = ResolveSessionUtils.safeFqNameForLazyResolve(psi);
|
||||
List<String> 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<KotlinObjectStub, J
|
||||
public void indexStub(@NotNull KotlinObjectStub stub, @NotNull IndexSink sink) {
|
||||
StubIndexServiceFactory.getInstance().indexObject(stub, sink);
|
||||
}
|
||||
|
||||
private static boolean isClassObject(@NotNull JetObjectDeclaration objectDeclaration) {
|
||||
return objectDeclaration.getParent() instanceof JetClassObject;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -31,8 +31,6 @@ public interface JetStubElementTypes {
|
||||
|
||||
JetClassElementType ENUM_ENTRY = new JetClassElementType("ENUM_ENTRY");
|
||||
JetObjectElementType OBJECT_DECLARATION = new JetObjectElementType("OBJECT_DECLARATION");
|
||||
JetPlaceHolderStubElementType<JetClassObject> CLASS_OBJECT =
|
||||
new JetPlaceHolderStubElementType<JetClassObject>("CLASS_OBJECT", JetClassObject.class);
|
||||
JetPlaceHolderStubElementType<JetClassInitializer> ANONYMOUS_INITIALIZER =
|
||||
new JetPlaceHolderStubElementType<JetClassInitializer>("ANONYMOUS_INITIALIZER", JetClassInitializer.class);
|
||||
|
||||
@@ -115,7 +113,7 @@ public interface JetStubElementTypes {
|
||||
new JetPlaceHolderStubElementType<JetConstructorCalleeExpression>("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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
-10
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -46,7 +46,7 @@ public class JetClassInfo extends JetClassOrObjectInfo<JetClass> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetClassObject getClassObject() {
|
||||
public JetObjectDeclaration getClassObject() {
|
||||
return element.getClassObject();
|
||||
}
|
||||
|
||||
|
||||
@@ -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<JetClassObject> getClassObjects();
|
||||
List<JetObjectDeclaration> getClassObjects();
|
||||
|
||||
// This element is used to identify resolution scope for the class
|
||||
@NotNull
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ public abstract class JetClassOrObjectInfo<E extends JetClassOrObject> implement
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetClassObject> getClassObjects() {
|
||||
public List<JetObjectDeclaration> getClassObjects() {
|
||||
JetClassBody body = element.getBody();
|
||||
if (body == null) {
|
||||
return Collections.emptyList();
|
||||
|
||||
@@ -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<JetObjectDeclaration> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetClassObject getClassObject() {
|
||||
public JetObjectDeclaration getClassObject() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public class JetScriptInfo(
|
||||
override fun getContainingPackageFqName() = fqName.parent()
|
||||
override fun getModifierList() = null
|
||||
override fun getClassObject() = null
|
||||
override fun getClassObjects() = listOf<JetClassObject>()
|
||||
override fun getClassObjects() = listOf<JetObjectDeclaration>()
|
||||
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()
|
||||
}
|
||||
|
||||
+1
-6
@@ -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()) {
|
||||
|
||||
+13
-13
@@ -83,7 +83,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
private final Annotations annotations;
|
||||
private final Annotations danglingAnnotations;
|
||||
private final NullableLazyValue<LazyClassDescriptor> classObjectDescriptor;
|
||||
private final MemoizedFunctionToNotNull<JetClassObject, ClassDescriptor> extraClassObjectDescriptors;
|
||||
private final MemoizedFunctionToNotNull<JetObjectDeclaration, ClassDescriptor> 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<JetClassObject, ClassDescriptor>() {
|
||||
this.extraClassObjectDescriptors = storageManager.createMemoizedFunction(new Function1<JetObjectDeclaration, ClassDescriptor>() {
|
||||
@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<ClassDescriptor> getDescriptorsForExtraClassObjects() {
|
||||
final JetClassObject allowedClassObject = getClassObjectIfAllowed();
|
||||
final JetObjectDeclaration allowedClassObject = getClassObjectIfAllowed();
|
||||
|
||||
return KotlinPackage.map(
|
||||
KotlinPackage.filter(
|
||||
declarationProvider.getOwnerInfo().getClassObjects(),
|
||||
new Function1<JetClassObject, Boolean>() {
|
||||
new Function1<JetObjectDeclaration, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(JetClassObject classObject) {
|
||||
public Boolean invoke(JetObjectDeclaration classObject) {
|
||||
return classObject != allowedClassObject;
|
||||
}
|
||||
}
|
||||
),
|
||||
new Function1<JetClassObject, ClassDescriptor>() {
|
||||
new Function1<JetObjectDeclaration, ClassDescriptor>() {
|
||||
@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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user