Move java visibilities to JavaVisibilities class
Move related utilities to where they're used
This commit is contained in:
committed by
Pavel V. Talanov
parent
e1a10eb419
commit
85e7b87ccd
@@ -65,12 +65,12 @@ public class AsmUtil {
|
|||||||
private static final Map<Visibility, Integer> visibilityToAccessFlag = ImmutableMap.<Visibility, Integer>builder()
|
private static final Map<Visibility, Integer> visibilityToAccessFlag = ImmutableMap.<Visibility, Integer>builder()
|
||||||
.put(Visibilities.PRIVATE, ACC_PRIVATE)
|
.put(Visibilities.PRIVATE, ACC_PRIVATE)
|
||||||
.put(Visibilities.PROTECTED, ACC_PROTECTED)
|
.put(Visibilities.PROTECTED, ACC_PROTECTED)
|
||||||
.put(JavaDescriptorResolver.PROTECTED_STATIC_VISIBILITY, ACC_PROTECTED)
|
.put(JavaVisibilities.PROTECTED_STATIC_VISIBILITY, ACC_PROTECTED)
|
||||||
.put(JavaDescriptorResolver.PROTECTED_AND_PACKAGE, ACC_PROTECTED)
|
.put(JavaVisibilities.PROTECTED_AND_PACKAGE, ACC_PROTECTED)
|
||||||
.put(Visibilities.PUBLIC, ACC_PUBLIC)
|
.put(Visibilities.PUBLIC, ACC_PUBLIC)
|
||||||
.put(Visibilities.INTERNAL, ACC_PUBLIC)
|
.put(Visibilities.INTERNAL, ACC_PUBLIC)
|
||||||
.put(Visibilities.LOCAL, NO_FLAG_LOCAL)
|
.put(Visibilities.LOCAL, NO_FLAG_LOCAL)
|
||||||
.put(JavaDescriptorResolver.PACKAGE_VISIBILITY, NO_FLAG_PACKAGE_PRIVATE)
|
.put(JavaVisibilities.PACKAGE_VISIBILITY, NO_FLAG_PACKAGE_PRIVATE)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static final String CAPTURED_RECEIVER_FIELD = "receiver$0";
|
public static final String CAPTURED_RECEIVER_FIELD = "receiver$0";
|
||||||
|
|||||||
+3
-11
@@ -94,11 +94,11 @@ public final class DescriptorResolverUtils {
|
|||||||
}
|
}
|
||||||
if (modifierListOwner.hasModifierProperty(PsiModifier.PROTECTED)) {
|
if (modifierListOwner.hasModifierProperty(PsiModifier.PROTECTED)) {
|
||||||
if (modifierListOwner.hasModifierProperty(PsiModifier.STATIC)) {
|
if (modifierListOwner.hasModifierProperty(PsiModifier.STATIC)) {
|
||||||
return JavaDescriptorResolver.PROTECTED_STATIC_VISIBILITY;
|
return JavaVisibilities.PROTECTED_STATIC_VISIBILITY;
|
||||||
}
|
}
|
||||||
return JavaDescriptorResolver.PROTECTED_AND_PACKAGE;
|
return JavaVisibilities.PROTECTED_AND_PACKAGE;
|
||||||
}
|
}
|
||||||
return JavaDescriptorResolver.PACKAGE_VISIBILITY;
|
return JavaVisibilities.PACKAGE_VISIBILITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -119,14 +119,6 @@ public final class DescriptorResolverUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Visibility getConstructorVisibility(ClassDescriptor classDescriptor) {
|
|
||||||
Visibility containingClassVisibility = classDescriptor.getVisibility();
|
|
||||||
if (containingClassVisibility == JavaDescriptorResolver.PROTECTED_STATIC_VISIBILITY) {
|
|
||||||
return JavaDescriptorResolver.PROTECTED_AND_PACKAGE;
|
|
||||||
}
|
|
||||||
return containingClassVisibility;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void checkPsiClassIsNotJet(@Nullable PsiClass psiClass) {
|
public static void checkPsiClassIsNotJet(@Nullable PsiClass psiClass) {
|
||||||
if (psiClass instanceof JetJavaMirrorMarker) {
|
if (psiClass instanceof JetJavaMirrorMarker) {
|
||||||
throw new IllegalStateException("trying to resolve fake jet PsiClass as regular PsiClass: " + psiClass.getQualifiedName());
|
throw new IllegalStateException("trying to resolve fake jet PsiClass as regular PsiClass: " + psiClass.getQualifiedName());
|
||||||
|
|||||||
-105
@@ -20,7 +20,6 @@ import com.intellij.psi.PsiClass;
|
|||||||
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.*;
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
|
||||||
import org.jetbrains.jet.lang.resolve.java.provider.NamedMembers;
|
import org.jetbrains.jet.lang.resolve.java.provider.NamedMembers;
|
||||||
import org.jetbrains.jet.lang.resolve.java.resolver.*;
|
import org.jetbrains.jet.lang.resolve.java.resolver.*;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
@@ -38,110 +37,6 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
|
|||||||
|
|
||||||
public static final Name JAVA_ROOT = Name.special("<java_root>");
|
public static final Name JAVA_ROOT = Name.special("<java_root>");
|
||||||
|
|
||||||
public static final Visibility PACKAGE_VISIBILITY = new Visibility("package", false) {
|
|
||||||
@Override
|
|
||||||
protected boolean isVisible(@NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
|
||||||
return DescriptorUtils.isInSameNamespace(what, from);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Integer compareTo(@NotNull Visibility visibility) {
|
|
||||||
if (this == visibility) return 0;
|
|
||||||
if (visibility == Visibilities.PRIVATE) return 1;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "public/*package*/";
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Visibility normalize() {
|
|
||||||
return Visibilities.INTERNAL;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public static final Visibility PROTECTED_STATIC_VISIBILITY = new Visibility("protected_static", false) {
|
|
||||||
@Override
|
|
||||||
protected boolean isVisible(@NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
|
||||||
ClassDescriptor fromClass = DescriptorUtils.getParentOfType(from, ClassDescriptor.class, false);
|
|
||||||
if (fromClass == null) return false;
|
|
||||||
|
|
||||||
ClassDescriptor whatClass;
|
|
||||||
// protected static class
|
|
||||||
if (what instanceof ClassDescriptor) {
|
|
||||||
DeclarationDescriptor containingDeclaration = what.getContainingDeclaration();
|
|
||||||
assert containingDeclaration instanceof ClassDescriptor : "Only static nested classes can have protected_static visibility";
|
|
||||||
whatClass = (ClassDescriptor) containingDeclaration;
|
|
||||||
}
|
|
||||||
// protected static function or property
|
|
||||||
else {
|
|
||||||
DeclarationDescriptor whatDeclarationDescriptor = what.getContainingDeclaration();
|
|
||||||
assert whatDeclarationDescriptor instanceof NamespaceDescriptor : "Only static declarations can have protected_static visibility";
|
|
||||||
whatClass = DescriptorUtils.getClassForCorrespondingJavaNamespace((NamespaceDescriptor) whatDeclarationDescriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
assert whatClass != null : "Couldn't find ClassDescriptor for protected static member " + what;
|
|
||||||
|
|
||||||
if (DescriptorUtils.isSubclass(fromClass, whatClass)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return isVisible(what, fromClass.getContainingDeclaration());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "protected/*protected static*/";
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Visibility normalize() {
|
|
||||||
return Visibilities.PROTECTED;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public static final Visibility PROTECTED_AND_PACKAGE = new Visibility("protected_and_package", false) {
|
|
||||||
@Override
|
|
||||||
protected boolean isVisible(@NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
|
||||||
if (DescriptorUtils.isInSameNamespace(what, from)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClassDescriptor whatClass = DescriptorUtils.getParentOfType(what, ClassDescriptor.class, false);
|
|
||||||
if (whatClass == null) return false;
|
|
||||||
|
|
||||||
ClassDescriptor fromClass = DescriptorUtils.getParentOfType(from, ClassDescriptor.class, false);
|
|
||||||
if (fromClass == null) return false;
|
|
||||||
|
|
||||||
if (DescriptorUtils.isSubclass(fromClass, whatClass)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return isVisible(what, fromClass.getContainingDeclaration());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Integer compareTo(@NotNull Visibility visibility) {
|
|
||||||
if (this == visibility) return 0;
|
|
||||||
if (visibility == Visibilities.INTERNAL) return null;
|
|
||||||
if (visibility == Visibilities.PRIVATE) return 1;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "protected/*protected and package*/";
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Visibility normalize() {
|
|
||||||
return Visibilities.PROTECTED;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private JavaPropertyResolver propertiesResolver;
|
private JavaPropertyResolver propertiesResolver;
|
||||||
private JavaClassResolver classResolver;
|
private JavaClassResolver classResolver;
|
||||||
private JavaConstructorResolver constructorResolver;
|
private JavaConstructorResolver constructorResolver;
|
||||||
|
|||||||
@@ -0,0 +1,165 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2013 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.lang.resolve.java;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.impl.NamespaceDescriptorParent;
|
||||||
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
|
|
||||||
|
public class JavaVisibilities {
|
||||||
|
private JavaVisibilities() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Visibility PACKAGE_VISIBILITY = new Visibility("package", false) {
|
||||||
|
@Override
|
||||||
|
protected boolean isVisible(@NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||||
|
return isInSameNamespace(what, from);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Integer compareTo(@NotNull Visibility visibility) {
|
||||||
|
if (this == visibility) return 0;
|
||||||
|
if (visibility == Visibilities.PRIVATE) return 1;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "public/*package*/";
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Visibility normalize() {
|
||||||
|
return Visibilities.INTERNAL;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static final Visibility PROTECTED_STATIC_VISIBILITY = new Visibility("protected_static", false) {
|
||||||
|
@Override
|
||||||
|
protected boolean isVisible(@NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||||
|
ClassDescriptor fromClass = DescriptorUtils.getParentOfType(from, ClassDescriptor.class, false);
|
||||||
|
if (fromClass == null) return false;
|
||||||
|
|
||||||
|
ClassDescriptor whatClass;
|
||||||
|
// protected static class
|
||||||
|
if (what instanceof ClassDescriptor) {
|
||||||
|
DeclarationDescriptor containingDeclaration = what.getContainingDeclaration();
|
||||||
|
assert containingDeclaration instanceof ClassDescriptor : "Only static nested classes can have protected_static visibility";
|
||||||
|
whatClass = (ClassDescriptor) containingDeclaration;
|
||||||
|
}
|
||||||
|
// protected static function or property
|
||||||
|
else {
|
||||||
|
DeclarationDescriptor whatDeclarationDescriptor = what.getContainingDeclaration();
|
||||||
|
assert whatDeclarationDescriptor instanceof NamespaceDescriptor : "Only static declarations can have protected_static visibility";
|
||||||
|
whatClass = getClassForCorrespondingJavaNamespace((NamespaceDescriptor) whatDeclarationDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert whatClass != null : "Couldn't find ClassDescriptor for protected static member " + what;
|
||||||
|
|
||||||
|
if (DescriptorUtils.isSubclass(fromClass, whatClass)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return isVisible(what, fromClass.getContainingDeclaration());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "protected/*protected static*/";
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Visibility normalize() {
|
||||||
|
return Visibilities.PROTECTED;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static final Visibility PROTECTED_AND_PACKAGE = new Visibility("protected_and_package", false) {
|
||||||
|
@Override
|
||||||
|
protected boolean isVisible(@NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||||
|
if (isInSameNamespace(what, from)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClassDescriptor whatClass = DescriptorUtils.getParentOfType(what, ClassDescriptor.class, false);
|
||||||
|
if (whatClass == null) return false;
|
||||||
|
|
||||||
|
ClassDescriptor fromClass = DescriptorUtils.getParentOfType(from, ClassDescriptor.class, false);
|
||||||
|
if (fromClass == null) return false;
|
||||||
|
|
||||||
|
if (DescriptorUtils.isSubclass(fromClass, whatClass)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return isVisible(what, fromClass.getContainingDeclaration());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Integer compareTo(@NotNull Visibility visibility) {
|
||||||
|
if (this == visibility) return 0;
|
||||||
|
if (visibility == Visibilities.INTERNAL) return null;
|
||||||
|
if (visibility == Visibilities.PRIVATE) return 1;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "protected/*protected and package*/";
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Visibility normalize() {
|
||||||
|
return Visibilities.PROTECTED;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private static boolean isInSameNamespace(@NotNull DeclarationDescriptor first, @NotNull DeclarationDescriptor second) {
|
||||||
|
NamespaceDescriptor whatPackage = DescriptorUtils.getParentOfType(first, NamespaceDescriptor.class, false);
|
||||||
|
NamespaceDescriptor fromPackage = DescriptorUtils.getParentOfType(second, NamespaceDescriptor.class, false);
|
||||||
|
return fromPackage != null && whatPackage != null && whatPackage.equals(fromPackage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static ClassDescriptor getClassForCorrespondingJavaNamespace(@NotNull NamespaceDescriptor correspondingNamespace) {
|
||||||
|
NamespaceDescriptorParent containingDeclaration = correspondingNamespace.getContainingDeclaration();
|
||||||
|
if (!(containingDeclaration instanceof NamespaceDescriptor)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
NamespaceDescriptor namespaceDescriptor = (NamespaceDescriptor) containingDeclaration;
|
||||||
|
|
||||||
|
ClassifierDescriptor classDescriptor = namespaceDescriptor.getMemberScope().getClassifier(correspondingNamespace.getName());
|
||||||
|
if (classDescriptor != null && classDescriptor instanceof ClassDescriptor) {
|
||||||
|
return (ClassDescriptor) classDescriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClassDescriptor classDescriptorForOuterClass = getClassForCorrespondingJavaNamespace(namespaceDescriptor);
|
||||||
|
if (classDescriptorForOuterClass == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClassifierDescriptor innerClassDescriptor =
|
||||||
|
classDescriptorForOuterClass.getUnsubstitutedInnerClassesScope().getClassifier(correspondingNamespace.getName());
|
||||||
|
if (innerClassDescriptor instanceof ClassDescriptor) {
|
||||||
|
return (ClassDescriptor) innerClassDescriptor;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
-1
@@ -86,7 +86,7 @@ public final class JavaConstructorResolver {
|
|||||||
constructors.add(trace.get(BindingContext.CONSTRUCTOR, psiClass));
|
constructors.add(trace.get(BindingContext.CONSTRUCTOR, psiClass));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Visibility constructorVisibility = DescriptorResolverUtils.getConstructorVisibility(containingClass);
|
Visibility constructorVisibility = getConstructorVisibility(containingClass);
|
||||||
// We need to create default constructors for classes and abstract classes.
|
// We need to create default constructors for classes and abstract classes.
|
||||||
// Example:
|
// Example:
|
||||||
// class Kotlin() : Java() {}
|
// class Kotlin() : Java() {}
|
||||||
@@ -161,6 +161,15 @@ public final class JavaConstructorResolver {
|
|||||||
return constructors;
|
return constructors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static Visibility getConstructorVisibility(@NotNull ClassDescriptor classDescriptor) {
|
||||||
|
Visibility visibility = classDescriptor.getVisibility();
|
||||||
|
if (visibility == JavaVisibilities.PROTECTED_STATIC_VISIBILITY) {
|
||||||
|
return JavaVisibilities.PROTECTED_AND_PACKAGE;
|
||||||
|
}
|
||||||
|
return visibility;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private ConstructorDescriptor resolveConstructor(
|
private ConstructorDescriptor resolveConstructor(
|
||||||
PsiClass psiClass,
|
PsiClass psiClass,
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.impl.AnonymousFunctionDescriptor;
|
import org.jetbrains.jet.lang.descriptors.impl.AnonymousFunctionDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.impl.NamespaceDescriptorParent;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetElement;
|
import org.jetbrains.jet.lang.psi.JetElement;
|
||||||
import org.jetbrains.jet.lang.psi.JetFunction;
|
import org.jetbrains.jet.lang.psi.JetFunction;
|
||||||
import org.jetbrains.jet.lang.psi.JetParameter;
|
import org.jetbrains.jet.lang.psi.JetParameter;
|
||||||
@@ -36,7 +35,10 @@ import org.jetbrains.jet.lang.resolve.name.Name;
|
|||||||
import org.jetbrains.jet.lang.resolve.scopes.FilteringScope;
|
import org.jetbrains.jet.lang.resolve.scopes.FilteringScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||||
import org.jetbrains.jet.lang.types.*;
|
import org.jetbrains.jet.lang.types.DescriptorSubstitutor;
|
||||||
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
|
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||||
|
import org.jetbrains.jet.lang.types.Variance;
|
||||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||||
@@ -44,7 +46,6 @@ import org.jetbrains.jet.renderer.DescriptorRenderer;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
|
import static org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
|
||||||
import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.DONT_CARE;
|
|
||||||
|
|
||||||
public class DescriptorUtils {
|
public class DescriptorUtils {
|
||||||
|
|
||||||
@@ -144,12 +145,6 @@ public class DescriptorUtils {
|
|||||||
return descriptor.getContainingDeclaration() instanceof NamespaceDescriptor;
|
return descriptor.getContainingDeclaration() instanceof NamespaceDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isInSameNamespace(@NotNull DeclarationDescriptor first, @NotNull DeclarationDescriptor second) {
|
|
||||||
NamespaceDescriptor whatPackage = DescriptorUtils.getParentOfType(first, NamespaceDescriptor.class, false);
|
|
||||||
NamespaceDescriptor fromPackage = DescriptorUtils.getParentOfType(second, NamespaceDescriptor.class, false);
|
|
||||||
return fromPackage != null && whatPackage != null && whatPackage.equals(fromPackage);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isInSameModule(@NotNull DeclarationDescriptor first, @NotNull DeclarationDescriptor second) {
|
public static boolean isInSameModule(@NotNull DeclarationDescriptor first, @NotNull DeclarationDescriptor second) {
|
||||||
ModuleDescriptor parentModule = DescriptorUtils.getParentOfType(first, ModuleDescriptorImpl.class, false);
|
ModuleDescriptor parentModule = DescriptorUtils.getParentOfType(first, ModuleDescriptorImpl.class, false);
|
||||||
ModuleDescriptor fromModule = DescriptorUtils.getParentOfType(second, ModuleDescriptorImpl.class, false);
|
ModuleDescriptor fromModule = DescriptorUtils.getParentOfType(second, ModuleDescriptorImpl.class, false);
|
||||||
@@ -528,33 +523,6 @@ public class DescriptorUtils {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static ClassDescriptor getClassForCorrespondingJavaNamespace(@NotNull NamespaceDescriptor correspondingNamespace) {
|
|
||||||
NamespaceDescriptorParent containingDeclaration = correspondingNamespace.getContainingDeclaration();
|
|
||||||
if (!(containingDeclaration instanceof NamespaceDescriptor)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
NamespaceDescriptor namespaceDescriptor = (NamespaceDescriptor) containingDeclaration;
|
|
||||||
|
|
||||||
ClassifierDescriptor classDescriptor = namespaceDescriptor.getMemberScope().getClassifier(correspondingNamespace.getName());
|
|
||||||
if (classDescriptor != null && classDescriptor instanceof ClassDescriptor) {
|
|
||||||
return (ClassDescriptor) classDescriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClassDescriptor classDescriptorForOuterClass = getClassForCorrespondingJavaNamespace(namespaceDescriptor);
|
|
||||||
if (classDescriptorForOuterClass == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClassifierDescriptor innerClassDescriptor =
|
|
||||||
classDescriptorForOuterClass.getUnsubstitutedInnerClassesScope().getClassifier(correspondingNamespace.getName());
|
|
||||||
if (innerClassDescriptor instanceof ClassDescriptor) {
|
|
||||||
return (ClassDescriptor) innerClassDescriptor;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isEnumValueOfMethod(@NotNull FunctionDescriptor functionDescriptor) {
|
public static boolean isEnumValueOfMethod(@NotNull FunctionDescriptor functionDescriptor) {
|
||||||
List<ValueParameterDescriptor> methodTypeParameters = functionDescriptor.getValueParameters();
|
List<ValueParameterDescriptor> methodTypeParameters = functionDescriptor.getValueParameters();
|
||||||
JetType nullableString = TypeUtils.makeNullable(KotlinBuiltIns.getInstance().getStringType());
|
JetType nullableString = TypeUtils.makeNullable(KotlinBuiltIns.getInstance().getStringType());
|
||||||
|
|||||||
Reference in New Issue
Block a user