use of org.jetbrains.kotlin.descriptors.ClassifierDescriptor in project kotlin by JetBrains.
the class MoveKotlinNestedClassesToUpperLevelDialog method getTargetContainerWithValidation.
@Nullable
private PsiElement getTargetContainerWithValidation() throws ConfigurationException {
String className = getClassName();
String parameterName = getParameterName();
if (className != null && className.isEmpty())
throw new ConfigurationException(RefactoringBundle.message("no.class.name.specified"));
if (!KotlinNameSuggester.INSTANCE.isIdentifier(className))
throw new ConfigurationException(RefactoringMessageUtil.getIncorrectIdentifierMessage(className));
if (passOuterClassCheckBox.isSelected()) {
if (parameterName != null && parameterName.isEmpty())
throw new ConfigurationException(RefactoringBundle.message("no.parameter.name.specified"));
if (!KotlinNameSuggester.INSTANCE.isIdentifier(parameterName))
throw new ConfigurationException(RefactoringMessageUtil.getIncorrectIdentifierMessage(parameterName));
}
PsiElement targetContainer = getTargetContainer();
if (targetContainer instanceof KtClassOrObject) {
KtClassOrObject targetClass = (KtClassOrObject) targetContainer;
for (KtDeclaration member : targetClass.getDeclarations()) {
if (member instanceof KtClassOrObject && className != null && className.equals(member.getName())) {
throw new ConfigurationException(RefactoringBundle.message("inner.class.exists", className, targetClass.getName()));
}
}
}
if (targetContainer instanceof PsiDirectory || targetContainer instanceof KtFile) {
FqName targetPackageFqName = getTargetPackageFqName();
if (targetPackageFqName == null)
throw new ConfigurationException("No package corresponds to this directory");
//noinspection ConstantConditions
ClassifierDescriptor existingClass = DescriptorUtils.getContainingModule(innerClassDescriptor).getPackage(targetPackageFqName).getMemberScope().getContributedClassifier(Name.identifier(className), NoLookupLocation.FROM_IDE);
if (existingClass != null)
throw new ConfigurationException("Class " + className + " already exists in package " + targetPackageFqName);
PsiDirectory targetDir = targetContainer instanceof PsiDirectory ? (PsiDirectory) targetContainer : targetContainer.getContainingFile().getContainingDirectory();
String message = RefactoringMessageUtil.checkCanCreateFile(targetDir, className + ".kt");
if (message != null)
throw new ConfigurationException(message);
}
return targetContainer;
}
use of org.jetbrains.kotlin.descriptors.ClassifierDescriptor in project kotlin by JetBrains.
the class TypeReconstructionUtil method allStarProjectionsString.
@NotNull
private static String allStarProjectionsString(@NotNull TypeConstructor constructor) {
int size = constructor.getParameters().size();
assert size != 0 : "No projections possible for a nilary type constructor" + constructor;
ClassifierDescriptor declarationDescriptor = constructor.getDeclarationDescriptor();
assert declarationDescriptor != null : "No declaration descriptor for type constructor " + constructor;
String name = declarationDescriptor.getName().asString();
return getTypeNameAndStarProjectionsString(name, size);
}
use of org.jetbrains.kotlin.descriptors.ClassifierDescriptor in project kotlin by JetBrains.
the class ReifiedTypeParameterSubstitutionChecker method check.
@Override
public void check(@NotNull ResolvedCall<?> resolvedCall, @NotNull PsiElement reportOn, @NotNull CallCheckerContext context) {
Map<TypeParameterDescriptor, KotlinType> typeArguments = resolvedCall.getTypeArguments();
for (Map.Entry<TypeParameterDescriptor, KotlinType> entry : typeArguments.entrySet()) {
TypeParameterDescriptor parameter = entry.getKey();
KotlinType argument = entry.getValue();
ClassifierDescriptor argumentDeclarationDescriptor = argument.getConstructor().getDeclarationDescriptor();
if (!parameter.isReified() && !isTypeParameterOfKotlinArray(parameter)) {
continue;
}
KtTypeProjection typeProjection = CollectionsKt.getOrNull(resolvedCall.getCall().getTypeArguments(), parameter.getIndex());
PsiElement reportErrorOn = typeProjection != null ? typeProjection : reportOn;
if (argumentDeclarationDescriptor instanceof TypeParameterDescriptor && !((TypeParameterDescriptor) argumentDeclarationDescriptor).isReified()) {
context.getTrace().report(Errors.TYPE_PARAMETER_AS_REIFIED.on(reportErrorOn, (TypeParameterDescriptor) argumentDeclarationDescriptor));
} else if (TypeUtilsKt.cannotBeReified(argument)) {
context.getTrace().report(Errors.REIFIED_TYPE_FORBIDDEN_SUBSTITUTION.on(reportErrorOn, argument));
}
// REIFIED_TYPE_UNSAFE_SUBSTITUTION is temporary disabled because it seems too strict now (see KT-10847)
//else if (TypeUtilsKt.unsafeAsReifiedArgument(argument) && !hasPureReifiableAnnotation(parameter)) {
// context.getTrace().report(Errors.REIFIED_TYPE_UNSAFE_SUBSTITUTION.on(reportErrorOn, argument));
//}
}
}
use of org.jetbrains.kotlin.descriptors.ClassifierDescriptor in project kotlin by JetBrains.
the class ResolveSessionUtils method findClassByRelativePath.
@Nullable
public static ClassDescriptor findClassByRelativePath(@NotNull MemberScope packageScope, @NotNull FqName path) {
if (path.isRoot())
return null;
MemberScope scope = packageScope;
ClassifierDescriptor classifier = null;
for (Name name : path.pathSegments()) {
classifier = scope.getContributedClassifier(name, NoLookupLocation.WHEN_FIND_BY_FQNAME);
if (!(classifier instanceof ClassDescriptor))
return null;
scope = ((ClassDescriptor) classifier).getUnsubstitutedInnerClassesScope();
}
return (ClassDescriptor) classifier;
}
Aggregations