Support static class scope in frontend, JVM codegen and IDE
This commit is contained in:
@@ -1869,7 +1869,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
DeclarationDescriptor containingDeclaration = propertyDescriptor.getContainingDeclaration();
|
DeclarationDescriptor containingDeclaration = propertyDescriptor.getContainingDeclaration();
|
||||||
|
|
||||||
boolean isBackingFieldInAnotherClass = AsmUtil.isPropertyWithBackingFieldInOuterClass(propertyDescriptor);
|
boolean isBackingFieldInAnotherClass = AsmUtil.isPropertyWithBackingFieldInOuterClass(propertyDescriptor);
|
||||||
boolean isStatic = containingDeclaration instanceof PackageFragmentDescriptor;
|
boolean isStatic = DescriptorUtils.isStaticDeclaration(propertyDescriptor);
|
||||||
boolean isSuper = superExpression != null;
|
boolean isSuper = superExpression != null;
|
||||||
boolean isExtensionProperty = propertyDescriptor.getReceiverParameter() != null;
|
boolean isExtensionProperty = propertyDescriptor.getReceiverParameter() != null;
|
||||||
|
|
||||||
|
|||||||
@@ -443,7 +443,9 @@ public class JetTypeMapper {
|
|||||||
thisClass = mapClass(currentOwner);
|
thisClass = mapClass(currentOwner);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (isAccessor(functionDescriptor) || isPlatformStaticInObject(functionDescriptor)) {
|
if (isStaticDeclaration(functionDescriptor) ||
|
||||||
|
isAccessor(functionDescriptor) ||
|
||||||
|
isPlatformStaticInObject(functionDescriptor)) {
|
||||||
invokeOpcode = INVOKESTATIC;
|
invokeOpcode = INVOKESTATIC;
|
||||||
}
|
}
|
||||||
else if (isInterface) {
|
else if (isInterface) {
|
||||||
|
|||||||
+1
-1
@@ -47,7 +47,7 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet
|
|||||||
if (descriptor.isVar()) {
|
if (descriptor.isVar()) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (DescriptorUtils.isClassObject(descriptor.getContainingDeclaration()) || DescriptorUtils.isTopLevelDeclaration(descriptor)) {
|
if (DescriptorUtils.isClassObject(descriptor.getContainingDeclaration()) || DescriptorUtils.isStaticDeclaration(descriptor)) {
|
||||||
val returnType = descriptor.getType()
|
val returnType = descriptor.getType()
|
||||||
return KotlinBuiltIns.getInstance().isPrimitiveType(returnType) || KotlinBuiltIns.getInstance().getStringType() == returnType
|
return KotlinBuiltIns.getInstance().isPrimitiveType(returnType) || KotlinBuiltIns.getInstance().getStringType() == returnType
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,12 +86,13 @@ public interface Importer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void importAllUnderDeclaration(@NotNull DeclarationDescriptor descriptor, @NotNull PlatformToKotlinClassMap platformToKotlinClassMap) {
|
protected void importAllUnderDeclaration(@NotNull DeclarationDescriptor descriptor, @NotNull PlatformToKotlinClassMap platformToKotlinClassMap) {
|
||||||
List<JetScope> scopesToImport = new ArrayList<JetScope>(2);
|
List<JetScope> scopesToImport = new ArrayList<JetScope>(3);
|
||||||
if (descriptor instanceof PackageViewDescriptor) {
|
if (descriptor instanceof PackageViewDescriptor) {
|
||||||
scopesToImport.add(((PackageViewDescriptor) descriptor).getMemberScope());
|
scopesToImport.add(((PackageViewDescriptor) descriptor).getMemberScope());
|
||||||
}
|
}
|
||||||
else if (descriptor instanceof ClassDescriptor && ((ClassDescriptor) descriptor).getKind() != ClassKind.OBJECT) {
|
else if (descriptor instanceof ClassDescriptor && ((ClassDescriptor) descriptor).getKind() != ClassKind.OBJECT) {
|
||||||
ClassDescriptor classDescriptor = (ClassDescriptor) descriptor;
|
ClassDescriptor classDescriptor = (ClassDescriptor) descriptor;
|
||||||
|
scopesToImport.add(classDescriptor.getStaticScope());
|
||||||
scopesToImport.add(classDescriptor.getUnsubstitutedInnerClassesScope());
|
scopesToImport.add(classDescriptor.getUnsubstitutedInnerClassesScope());
|
||||||
ClassDescriptor classObjectDescriptor = classDescriptor.getClassObjectDescriptor();
|
ClassDescriptor classObjectDescriptor = classDescriptor.getClassObjectDescriptor();
|
||||||
if (classObjectDescriptor != null) {
|
if (classObjectDescriptor != null) {
|
||||||
|
|||||||
+23
-15
@@ -21,6 +21,7 @@ import com.google.common.collect.Collections2;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import kotlin.jvm.KotlinSignature;
|
import kotlin.jvm.KotlinSignature;
|
||||||
|
import org.jetbrains.annotations.Mutable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
@@ -232,35 +233,42 @@ public class QualifiedExpressionResolver {
|
|||||||
@NotNull LookupMode lookupMode,
|
@NotNull LookupMode lookupMode,
|
||||||
boolean storeResult
|
boolean storeResult
|
||||||
) {
|
) {
|
||||||
Set<SuccessfulLookupResult> results = Sets.newHashSet();
|
Set<SuccessfulLookupResult> results = Sets.newLinkedHashSet();
|
||||||
for (DeclarationDescriptor declarationDescriptor : declarationDescriptors) {
|
for (DeclarationDescriptor declarationDescriptor : declarationDescriptors) {
|
||||||
if (declarationDescriptor instanceof PackageViewDescriptor) {
|
if (declarationDescriptor instanceof PackageViewDescriptor) {
|
||||||
addResult(results, lookupSimpleNameReference(selector, ((PackageViewDescriptor) declarationDescriptor).getMemberScope(),
|
addResult(results, lookupSimpleNameReference(selector, ((PackageViewDescriptor) declarationDescriptor).getMemberScope(),
|
||||||
lookupMode, true));
|
lookupMode, true));
|
||||||
}
|
}
|
||||||
if (declarationDescriptor instanceof ClassDescriptor) {
|
if (declarationDescriptor instanceof ClassDescriptor) {
|
||||||
addResult(results, lookupSimpleNameReference(selector, getAppropriateScope((ClassDescriptor) declarationDescriptor,
|
addResultsForClass(results, selector, lookupMode, (ClassDescriptor) declarationDescriptor);
|
||||||
lookupMode), lookupMode, false));
|
|
||||||
ClassDescriptor classObjectDescriptor = ((ClassDescriptor) declarationDescriptor).getClassObjectDescriptor();
|
|
||||||
if (classObjectDescriptor != null) {
|
|
||||||
addResult(results, lookupSimpleNameReference(selector, getAppropriateScope(classObjectDescriptor, lookupMode),
|
|
||||||
lookupMode, false));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return filterAndStoreResolutionResult(results, selector, trace, scopeToCheckVisibility, lookupMode, storeResult);
|
return filterAndStoreResolutionResult(results, selector, trace, scopeToCheckVisibility, lookupMode, storeResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
private static void addResultsForClass(
|
||||||
private static JetScope getAppropriateScope(@NotNull ClassDescriptor classDescriptor, @NotNull LookupMode lookupMode) {
|
@NotNull @Mutable Set<SuccessfulLookupResult> results,
|
||||||
return lookupMode == LookupMode.ONLY_CLASSES
|
@NotNull JetSimpleNameExpression selector,
|
||||||
? classDescriptor.getUnsubstitutedInnerClassesScope()
|
@NotNull LookupMode lookupMode,
|
||||||
: classDescriptor.getDefaultType().getMemberScope();
|
@NotNull ClassDescriptor descriptor
|
||||||
|
) {
|
||||||
|
JetScope scope = lookupMode == LookupMode.ONLY_CLASSES
|
||||||
|
? descriptor.getUnsubstitutedInnerClassesScope()
|
||||||
|
: descriptor.getDefaultType().getMemberScope();
|
||||||
|
addResult(results, lookupSimpleNameReference(selector, scope, lookupMode, false));
|
||||||
|
|
||||||
|
addResult(results, lookupSimpleNameReference(selector, descriptor.getStaticScope(), lookupMode, true));
|
||||||
|
|
||||||
|
ClassDescriptor classObject = descriptor.getClassObjectDescriptor();
|
||||||
|
if (classObject != null) {
|
||||||
|
addResultsForClass(results, selector, lookupMode, classObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addResult(@NotNull Set<SuccessfulLookupResult> results, @NotNull LookupResult result) {
|
private static void addResult(@NotNull Set<SuccessfulLookupResult> results, @NotNull LookupResult result) {
|
||||||
if (result == LookupResult.EMPTY) return;
|
if (result != LookupResult.EMPTY) {
|
||||||
results.add((SuccessfulLookupResult) result);
|
results.add((SuccessfulLookupResult) result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+14
-17
@@ -16,13 +16,10 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve.scopes.receivers
|
package org.jetbrains.jet.lang.resolve.scopes.receivers
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.descriptors.*
|
||||||
import org.jetbrains.jet.lang.types.JetType
|
import org.jetbrains.jet.lang.types.JetType
|
||||||
import org.jetbrains.jet.lang.descriptors.PackageViewDescriptor
|
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor
|
|
||||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
|
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassKind
|
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils.getFqName
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils.getFqName
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name
|
import org.jetbrains.jet.lang.resolve.name.Name
|
||||||
@@ -30,17 +27,13 @@ import org.jetbrains.jet.lang.resolve.scopes.ChainedScope
|
|||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
import org.jetbrains.jet.utils.addIfNotNull
|
import org.jetbrains.jet.utils.addIfNotNull
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext.*
|
import org.jetbrains.jet.lang.resolve.BindingContext.*
|
||||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor
|
|
||||||
import org.jetbrains.jet.lang.diagnostics.Errors.*
|
import org.jetbrains.jet.lang.diagnostics.Errors.*
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
|
||||||
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor
|
|
||||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingContext
|
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingContext
|
||||||
import org.jetbrains.jet.lang.psi.psiUtil.getTopmostParentQualifiedExpressionForSelector
|
import org.jetbrains.jet.lang.psi.psiUtil.getTopmostParentQualifiedExpressionForSelector
|
||||||
import org.jetbrains.jet.lang.resolve.descriptorUtil.getClassObjectReferenceTarget
|
import org.jetbrains.jet.lang.resolve.descriptorUtil.getClassObjectReferenceTarget
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression
|
import org.jetbrains.jet.lang.psi.JetExpression
|
||||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.recordScopeAndDataFlowInfo
|
import org.jetbrains.jet.lang.resolve.bindingContextUtil.recordScopeAndDataFlowInfo
|
||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
import org.jetbrains.jet.lang.descriptors.PackageFragmentDescriptor
|
|
||||||
|
|
||||||
public trait Qualifier {
|
public trait Qualifier {
|
||||||
|
|
||||||
@@ -81,18 +74,22 @@ class QualifierReceiver (
|
|||||||
classifier?.getClassObjectType()?.let { ExpressionReceiver(referenceExpression, it) } ?: ReceiverValue.NO_RECEIVER
|
classifier?.getClassObjectType()?.let { ExpressionReceiver(referenceExpression, it) } ?: ReceiverValue.NO_RECEIVER
|
||||||
|
|
||||||
fun getNestedClassesAndPackageMembersScope(): JetScope {
|
fun getNestedClassesAndPackageMembersScope(): JetScope {
|
||||||
val scopes = ArrayList<JetScope>(3)
|
val scopes = ArrayList<JetScope>(4)
|
||||||
|
|
||||||
val classObjectDescriptor = (classifier as? ClassDescriptor)?.getClassObjectDescriptor()
|
|
||||||
if (classObjectDescriptor != null) {
|
|
||||||
// non-static members are resolved through class object receiver
|
|
||||||
scopes.add(DescriptorUtils.getStaticNestedClassesScope(classObjectDescriptor))
|
|
||||||
}
|
|
||||||
|
|
||||||
scopes.addIfNotNull(packageView?.getMemberScope())
|
scopes.addIfNotNull(packageView?.getMemberScope())
|
||||||
|
|
||||||
if (classifier is ClassDescriptor && classifier.getKind() != ClassKind.ENUM_ENTRY) {
|
if (classifier is ClassDescriptor) {
|
||||||
scopes.add(DescriptorUtils.getStaticNestedClassesScope(classifier))
|
scopes.add(classifier.getStaticScope())
|
||||||
|
|
||||||
|
val classObjectDescriptor = classifier.getClassObjectDescriptor()
|
||||||
|
if (classObjectDescriptor != null) {
|
||||||
|
// non-static members are resolved through class object receiver
|
||||||
|
scopes.add(DescriptorUtils.getStaticNestedClassesScope(classObjectDescriptor))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (classifier.getKind() != ClassKind.ENUM_ENTRY) {
|
||||||
|
scopes.add(DescriptorUtils.getStaticNestedClassesScope(classifier))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ChainedScope(descriptor, "Static scope for " + name + " as package or class or object", *scopes.copyToArray())
|
return ChainedScope(descriptor, "Static scope for " + name + " as package or class or object", *scopes.copyToArray())
|
||||||
|
|||||||
+4
@@ -68,6 +68,7 @@ public class LazyJavaClassMemberScope(
|
|||||||
emptyOrSingletonList(createDefaultConstructor())
|
emptyOrSingletonList(createDefaultConstructor())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun computeNonDeclaredFunctions(result: MutableCollection<SimpleFunctionDescriptor>, name: Name) {
|
override fun computeNonDeclaredFunctions(result: MutableCollection<SimpleFunctionDescriptor>, name: Name) {
|
||||||
val functionsFromSupertypes = getFunctionsFromSupertypes(name, getContainingDeclaration())
|
val functionsFromSupertypes = getFunctionsFromSupertypes(name, getContainingDeclaration())
|
||||||
result.addAll(DescriptorResolverUtils.resolveOverrides(name, functionsFromSupertypes, result, getContainingDeclaration(), c.errorReporter))
|
result.addAll(DescriptorResolverUtils.resolveOverrides(name, functionsFromSupertypes, result, getContainingDeclaration(), c.errorReporter))
|
||||||
@@ -237,6 +238,9 @@ public class LazyJavaClassMemberScope(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getExpectedThisObject(): ReceiverParameterDescriptor? =
|
||||||
|
DescriptorUtils.getExpectedThisObjectIfNeeded(getContainingDeclaration())
|
||||||
|
|
||||||
override fun getClassifier(name: Name): ClassifierDescriptor? = nestedClasses(name)
|
override fun getClassifier(name: Name): ClassifierDescriptor? = nestedClasses(name)
|
||||||
override fun getAllClassNames(): Collection<Name> = nestedClassIndex().keySet() + enumEntryIndex().keySet()
|
override fun getAllClassNames(): Collection<Name> = nestedClassIndex().keySet() + enumEntryIndex().keySet()
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -43,7 +43,6 @@ import java.util.LinkedHashSet
|
|||||||
import org.jetbrains.jet.lang.types.JetType
|
import org.jetbrains.jet.lang.types.JetType
|
||||||
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaPropertyDescriptor
|
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaPropertyDescriptor
|
||||||
import org.jetbrains.jet.lang.descriptors.impl.PropertyDescriptorImpl
|
import org.jetbrains.jet.lang.descriptors.impl.PropertyDescriptorImpl
|
||||||
import java.util.Collections
|
|
||||||
import org.jetbrains.jet.lang.resolve.java.resolver.ExternalSignatureResolver
|
import org.jetbrains.jet.lang.resolve.java.resolver.ExternalSignatureResolver
|
||||||
import org.jetbrains.jet.lang.resolve.java.sam.SingleAbstractMethodUtils
|
import org.jetbrains.jet.lang.resolve.java.sam.SingleAbstractMethodUtils
|
||||||
import org.jetbrains.jet.utils.*
|
import org.jetbrains.jet.utils.*
|
||||||
@@ -58,7 +57,7 @@ public abstract class LazyJavaMemberScope(
|
|||||||
// when computing getAllPackageNames() we ask the JavaPsiFacade for all subpackages of foo
|
// when computing getAllPackageNames() we ask the JavaPsiFacade for all subpackages of foo
|
||||||
// it, in turn, asks JavaElementFinder for subpackages of Kotlin package foo, which calls getAllPackageNames() recursively
|
// it, in turn, asks JavaElementFinder for subpackages of Kotlin package foo, which calls getAllPackageNames() recursively
|
||||||
// when on recursive call we return an empty collection, recursion collapses gracefully
|
// when on recursive call we return an empty collection, recursion collapses gracefully
|
||||||
Collections.emptyList()
|
listOf()
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun getContainingDeclaration() = _containingDeclaration
|
override fun getContainingDeclaration() = _containingDeclaration
|
||||||
@@ -71,6 +70,8 @@ public abstract class LazyJavaMemberScope(
|
|||||||
|
|
||||||
protected abstract fun computeNonDeclaredFunctions(result: MutableCollection<SimpleFunctionDescriptor>, name: Name)
|
protected abstract fun computeNonDeclaredFunctions(result: MutableCollection<SimpleFunctionDescriptor>, name: Name)
|
||||||
|
|
||||||
|
protected abstract fun getExpectedThisObject(): ReceiverParameterDescriptor?
|
||||||
|
|
||||||
private val _functions = c.storageManager.createMemoizedFunction {
|
private val _functions = c.storageManager.createMemoizedFunction {
|
||||||
(name: Name): Collection<FunctionDescriptor>
|
(name: Name): Collection<FunctionDescriptor>
|
||||||
->
|
->
|
||||||
@@ -138,7 +139,7 @@ public abstract class LazyJavaMemberScope(
|
|||||||
|
|
||||||
functionDescriptorImpl.initialize(
|
functionDescriptorImpl.initialize(
|
||||||
effectiveSignature.getReceiverType(),
|
effectiveSignature.getReceiverType(),
|
||||||
DescriptorUtils.getExpectedThisObjectIfNeeded(_containingDeclaration),
|
getExpectedThisObject(),
|
||||||
effectiveSignature.getTypeParameters(),
|
effectiveSignature.getTypeParameters(),
|
||||||
effectiveSignature.getValueParameters(),
|
effectiveSignature.getValueParameters(),
|
||||||
effectiveSignature.getReturnType(),
|
effectiveSignature.getReturnType(),
|
||||||
@@ -256,7 +257,7 @@ public abstract class LazyJavaMemberScope(
|
|||||||
c.externalSignatureResolver.reportSignatureErrors(propertyDescriptor, signatureErrors)
|
c.externalSignatureResolver.reportSignatureErrors(propertyDescriptor, signatureErrors)
|
||||||
}
|
}
|
||||||
|
|
||||||
propertyDescriptor.setType(effectiveSignature.getReturnType(), Collections.emptyList(), DescriptorUtils.getExpectedThisObjectIfNeeded(getContainingDeclaration()), null : JetType?)
|
propertyDescriptor.setType(effectiveSignature.getReturnType(), listOf(), getExpectedThisObject(), null : JetType?)
|
||||||
|
|
||||||
if (DescriptorUtils.shouldRecordInitializerForProperty(propertyDescriptor, propertyDescriptor.getType())) {
|
if (DescriptorUtils.shouldRecordInitializerForProperty(propertyDescriptor, propertyDescriptor.getType())) {
|
||||||
propertyDescriptor.setCompileTimeInitializer(
|
propertyDescriptor.setCompileTimeInitializer(
|
||||||
|
|||||||
+2
@@ -44,6 +44,8 @@ public abstract class LazyJavaStaticScope(
|
|||||||
|
|
||||||
protected val fqName: FqName = DescriptorUtils.getFqName(descriptor).toSafe()
|
protected val fqName: FqName = DescriptorUtils.getFqName(descriptor).toSafe()
|
||||||
|
|
||||||
|
override fun getExpectedThisObject() = null
|
||||||
|
|
||||||
protected fun computeMemberIndexForSamConstructors(delegate: MemberIndex): MemberIndex = object : MemberIndex by delegate {
|
protected fun computeMemberIndexForSamConstructors(delegate: MemberIndex): MemberIndex = object : MemberIndex by delegate {
|
||||||
override fun getAllMethodNames(): Collection<Name> {
|
override fun getAllMethodNames(): Collection<Name> {
|
||||||
val jClass = c.findClassInJava(fqName).jClass
|
val jClass = c.findClassInJava(fqName).jClass
|
||||||
|
|||||||
@@ -107,10 +107,6 @@ public class DescriptorUtils {
|
|||||||
return getFqName(containingDeclaration).child(descriptor.getName());
|
return getFqName(containingDeclaration).child(descriptor.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isTopLevelDeclaration(@NotNull DeclarationDescriptor descriptor) {
|
|
||||||
return descriptor.getContainingDeclaration() instanceof PackageFragmentDescriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static DeclarationDescriptor getContainingDeclarationSkippingClassObjects(@NotNull DeclarationDescriptor descriptor) {
|
private static DeclarationDescriptor getContainingDeclarationSkippingClassObjects(@NotNull DeclarationDescriptor descriptor) {
|
||||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||||
@@ -127,6 +123,22 @@ public class DescriptorUtils {
|
|||||||
return getFqNameFromTopLevelClass(containingDeclaration).child(name);
|
return getFqNameFromTopLevelClass(containingDeclaration).child(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isTopLevelDeclaration(@NotNull DeclarationDescriptor descriptor) {
|
||||||
|
return descriptor.getContainingDeclaration() instanceof PackageFragmentDescriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true iff this is a top-level declaration or a class member with no expected "this" object (e.g. static members in Java,
|
||||||
|
* values() and valueOf() methods of enum classes, etc.)
|
||||||
|
*/
|
||||||
|
public static boolean isStaticDeclaration(@NotNull CallableDescriptor descriptor) {
|
||||||
|
if (descriptor instanceof ConstructorDescriptor) return false;
|
||||||
|
|
||||||
|
DeclarationDescriptor container = descriptor.getContainingDeclaration();
|
||||||
|
return container instanceof PackageFragmentDescriptor ||
|
||||||
|
(container instanceof ClassDescriptor && descriptor.getExpectedThisObject() == null);
|
||||||
|
}
|
||||||
|
|
||||||
// WARNING! Don't use this method in JVM backend, use JvmCodegenUtil.isCallInsideSameModuleAsDeclared() instead.
|
// WARNING! Don't use this method in JVM backend, use JvmCodegenUtil.isCallInsideSameModuleAsDeclared() instead.
|
||||||
// The latter handles compilation against compiled part of our module correctly.
|
// The latter handles compilation against compiled part of our module correctly.
|
||||||
public static boolean areInSameModule(@NotNull DeclarationDescriptor first, @NotNull DeclarationDescriptor second) {
|
public static boolean areInSameModule(@NotNull DeclarationDescriptor first, @NotNull DeclarationDescriptor second) {
|
||||||
|
|||||||
+10
-9
@@ -77,21 +77,22 @@ class PropertiesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
|||||||
super.visitParameter(parameter);
|
super.visitParameter(parameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void highlightProperty(@NotNull PsiElement elementToHighlight,
|
private void highlightProperty(
|
||||||
|
@NotNull PsiElement elementToHighlight,
|
||||||
@NotNull PropertyDescriptor descriptor,
|
@NotNull PropertyDescriptor descriptor,
|
||||||
boolean withBackingField) {
|
boolean withBackingField
|
||||||
boolean inPackage = DescriptorUtils.isTopLevelDeclaration(descriptor);
|
) {
|
||||||
JetPsiChecker.highlightName(holder, elementToHighlight,
|
boolean isStatic = DescriptorUtils.isStaticDeclaration(descriptor);
|
||||||
inPackage ? JetHighlightingColors.PACKAGE_PROPERTY : JetHighlightingColors.INSTANCE_PROPERTY
|
JetPsiChecker.highlightName(
|
||||||
|
holder, elementToHighlight,
|
||||||
|
isStatic ? JetHighlightingColors.PACKAGE_PROPERTY : JetHighlightingColors.INSTANCE_PROPERTY
|
||||||
);
|
);
|
||||||
if (descriptor.getReceiverParameter() != null) {
|
if (descriptor.getReceiverParameter() != null) {
|
||||||
JetPsiChecker.highlightName(holder, elementToHighlight, JetHighlightingColors.EXTENSION_PROPERTY);
|
JetPsiChecker.highlightName(holder, elementToHighlight, JetHighlightingColors.EXTENSION_PROPERTY);
|
||||||
}
|
}
|
||||||
if (withBackingField) {
|
if (withBackingField) {
|
||||||
holder.createInfoAnnotation(
|
holder.createInfoAnnotation(elementToHighlight, "This property has a backing field")
|
||||||
elementToHighlight,
|
.setTextAttributes(JetHighlightingColors.PROPERTY_WITH_BACKING_FIELD);
|
||||||
"This property has a backing field")
|
|
||||||
.setTextAttributes(JetHighlightingColors.PROPERTY_WITH_BACKING_FIELD);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,9 @@ public val DeclarationDescriptor.importableFqNameSafe: FqName
|
|||||||
get() = DescriptorUtils.getFqNameSafe(getImportableDescriptor())
|
get() = DescriptorUtils.getFqNameSafe(getImportableDescriptor())
|
||||||
|
|
||||||
public fun DeclarationDescriptor.canBeReferencedViaImport(): Boolean {
|
public fun DeclarationDescriptor.canBeReferencedViaImport(): Boolean {
|
||||||
if (this is PackageViewDescriptor || DescriptorUtils.isTopLevelDeclaration(this)) {
|
if (this is PackageViewDescriptor ||
|
||||||
|
DescriptorUtils.isTopLevelDeclaration(this) ||
|
||||||
|
(this is CallableDescriptor && DescriptorUtils.isStaticDeclaration(this))) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
val parent = getContainingDeclaration()!!
|
val parent = getContainingDeclaration()!!
|
||||||
|
|||||||
Reference in New Issue
Block a user