Remove FqNameBase, simplify FqName and FqNameUnsafe
This commit is contained in:
+1
-1
@@ -312,7 +312,7 @@ public class SingleAbstractMethodUtils {
|
||||
@Nullable
|
||||
public static JavaMethod getSamInterfaceMethod(@NotNull JavaClass javaClass) {
|
||||
FqName fqName = javaClass.getFqName();
|
||||
if (fqName == null || fqName.firstSegmentIs(KotlinBuiltIns.BUILT_INS_PACKAGE_NAME)) {
|
||||
if (fqName == null || fqName.toUnsafe().startsWith(KotlinBuiltIns.BUILT_INS_PACKAGE_NAME)) {
|
||||
return null;
|
||||
}
|
||||
if (!javaClass.isInterface() || javaClass.isAnnotationType()) {
|
||||
|
||||
+9
-8
@@ -19,21 +19,21 @@ package org.jetbrains.kotlin.load.java
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature.getSpecialSignatureInfo
|
||||
import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature.sameAsBuiltinMethodWithErasedValueParameters
|
||||
import org.jetbrains.kotlin.load.java.BuiltinSpecialProperties.getBuiltinSpecialPropertyGetterName
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.types.checker.TypeCheckingProcedure
|
||||
import org.jetbrains.kotlin.utils.DFS
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.check
|
||||
import org.jetbrains.kotlin.load.java.BuiltinSpecialProperties.getBuiltinSpecialPropertyGetterName
|
||||
import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature.sameAsBuiltinMethodWithErasedValueParameters
|
||||
import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature.getSpecialSignatureInfo
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.types.checker.TypeCheckingProcedure
|
||||
|
||||
object BuiltinSpecialProperties {
|
||||
private val PROPERTY_FQ_NAME_TO_JVM_GETTER_NAME_MAP = mapOf(
|
||||
@@ -260,8 +260,9 @@ private val CallableMemberDescriptor.isFromJava: Boolean
|
||||
get() = propertyIfAccessor is JavaCallableMemberDescriptor && propertyIfAccessor.containingDeclaration is JavaClassDescriptor
|
||||
|
||||
private fun CallableMemberDescriptor.isFromBuiltins(): Boolean {
|
||||
if (!(propertyIfAccessor.fqNameOrNull()?.firstSegmentIs(KotlinBuiltIns.BUILT_INS_PACKAGE_NAME) ?: false)) return false
|
||||
return builtIns.builtInsModule == module
|
||||
val fqName = propertyIfAccessor.fqNameOrNull() ?: return false
|
||||
return fqName.toUnsafe().startsWith(KotlinBuiltIns.BUILT_INS_PACKAGE_NAME) &&
|
||||
this.module == this.builtIns.builtInsModule
|
||||
}
|
||||
|
||||
private val CallableMemberDescriptor.propertyIfAccessor: CallableMemberDescriptor
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.utils.StringsKt;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class FqName extends FqNameBase {
|
||||
public final class FqName {
|
||||
|
||||
@NotNull
|
||||
public static FqName fromSegments(@NotNull List<String> names) {
|
||||
@@ -55,7 +55,6 @@ public final class FqName extends FqNameBase {
|
||||
return qualifiedName.indexOf('<') < 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String asString() {
|
||||
return fqName.asString();
|
||||
@@ -95,7 +94,6 @@ public final class FqName extends FqNameBase {
|
||||
return fqName.shortName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Name shortNameOrSpecial() {
|
||||
return fqName.shortNameOrSpecial();
|
||||
@@ -115,20 +113,11 @@ public final class FqName extends FqNameBase {
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<Name> pathSegments() {
|
||||
return fqName.pathSegments();
|
||||
}
|
||||
|
||||
public boolean firstSegmentIs(@NotNull Name segment) {
|
||||
return fqName.firstSegmentIs(segment);
|
||||
}
|
||||
|
||||
public boolean lastSegmentIs(@NotNull Name segment) {
|
||||
return fqName.lastSegmentIs(segment);
|
||||
}
|
||||
|
||||
public boolean isAncestorOf(@NotNull FqName other) {
|
||||
String thisString = this.asString();
|
||||
String otherString = other.asString();
|
||||
@@ -140,7 +129,6 @@ public final class FqName extends FqNameBase {
|
||||
return new FqName(FqNameUnsafe.topLevel(shortName));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return fqName.toString();
|
||||
|
||||
@@ -1,61 +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.name;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class FqNameBase {
|
||||
|
||||
protected FqNameBase() {
|
||||
if (!(this instanceof FqName || this instanceof FqNameUnsafe)) {
|
||||
throw new AssertionError("do not use this class directly");
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract String asString();
|
||||
|
||||
@NotNull
|
||||
private FqNameUnsafe toFqNameUnsafe() {
|
||||
if (this instanceof FqName) {
|
||||
return ((FqName) this).toUnsafe();
|
||||
}
|
||||
else if (this instanceof FqNameUnsafe) {
|
||||
return ((FqNameUnsafe) this);
|
||||
}
|
||||
else {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
public final boolean equalsTo(@Nullable FqName that) {
|
||||
return that != null && equalsTo(that.toUnsafe());
|
||||
}
|
||||
|
||||
public final boolean equalsTo(@Nullable FqNameUnsafe that) {
|
||||
return toFqNameUnsafe().equals(that);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public abstract Name shortNameOrSpecial();
|
||||
|
||||
@NotNull
|
||||
public abstract List<Name> pathSegments();
|
||||
}
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.name;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.utils.StringsKt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -26,7 +25,7 @@ import java.util.List;
|
||||
/**
|
||||
* Like {@link FqName} but allows '<' and '>' characters in name.
|
||||
*/
|
||||
public final class FqNameUnsafe extends FqNameBase {
|
||||
public final class FqNameUnsafe {
|
||||
|
||||
public static final Name ROOT_NAME = Name.special("<root>");
|
||||
|
||||
@@ -70,9 +69,6 @@ public final class FqNameUnsafe extends FqNameBase {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String asString() {
|
||||
return fqName;
|
||||
@@ -140,7 +136,6 @@ public final class FqNameUnsafe extends FqNameBase {
|
||||
return shortName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Name shortNameOrSpecial() {
|
||||
if (isRoot()) {
|
||||
@@ -168,7 +163,6 @@ public final class FqNameUnsafe extends FqNameBase {
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<Name> pathSegments() {
|
||||
final List<Name> path = new ArrayList<Name>();
|
||||
@@ -181,7 +175,6 @@ public final class FqNameUnsafe extends FqNameBase {
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
void walk(@NotNull WalkCallback callback) {
|
||||
if (isRoot()) {
|
||||
return;
|
||||
@@ -226,33 +219,15 @@ public final class FqNameUnsafe extends FqNameBase {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean firstSegmentIs(@NotNull Name segment) {
|
||||
if (isRoot()) {
|
||||
return false;
|
||||
}
|
||||
List<Name> pathSegments = pathSegments();
|
||||
return pathSegments.get(0).equals(segment);
|
||||
public boolean startsWith(@NotNull Name segment) {
|
||||
return !isRoot() && pathSegments().get(0).equals(segment);
|
||||
}
|
||||
|
||||
public boolean lastSegmentIs(@NotNull Name segment) {
|
||||
if (isRoot()) {
|
||||
return false;
|
||||
}
|
||||
return shortName().equals(segment);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static FqNameUnsafe fromSegments(@NotNull List<?> names) {
|
||||
return new FqNameUnsafe(StringsKt.join(names, "."));
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public static FqNameUnsafe topLevel(@NotNull Name shortName) {
|
||||
return new FqNameUnsafe(shortName.asString(), FqName.ROOT.toUnsafe(), shortName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String toString() {
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.FqNameBase
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeConstructor
|
||||
@@ -55,7 +55,7 @@ public abstract class DescriptorRenderer : Renderer<DeclarationDescriptor> {
|
||||
|
||||
public abstract fun renderName(name: Name): String
|
||||
|
||||
public abstract fun renderFqName(fqName: FqNameBase): String
|
||||
public abstract fun renderFqName(fqName: FqNameUnsafe): String
|
||||
|
||||
public interface ValueParametersHandler {
|
||||
public fun appendBeforeValueParameters(parameterCount: Int, builder: StringBuilder)
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotated
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.name.FqNameBase
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
@@ -111,7 +111,7 @@ internal class DescriptorRendererImpl(
|
||||
}
|
||||
}
|
||||
|
||||
override fun renderFqName(fqName: FqNameBase) = renderFqName(fqName.pathSegments())
|
||||
override fun renderFqName(fqName: FqNameUnsafe) = renderFqName(fqName.pathSegments())
|
||||
|
||||
private fun renderFqName(pathSegments: List<Name>) = escape(org.jetbrains.kotlin.renderer.renderFqName(pathSegments))
|
||||
|
||||
@@ -836,7 +836,7 @@ internal class DescriptorRendererImpl(
|
||||
|
||||
private fun renderPackageView(packageView: PackageViewDescriptor, builder: StringBuilder) {
|
||||
builder.append(renderKeyword("package")).append(" ")
|
||||
builder.append(renderFqName(packageView.fqName))
|
||||
builder.append(renderFqName(packageView.fqName.toUnsafe()))
|
||||
if (debugMode) {
|
||||
builder.append(" in context of ")
|
||||
renderName(packageView.module, builder)
|
||||
@@ -845,7 +845,7 @@ internal class DescriptorRendererImpl(
|
||||
|
||||
private fun renderPackageFragment(fragment: PackageFragmentDescriptor, builder: StringBuilder) {
|
||||
builder.append(renderKeyword("package-fragment")).append(" ")
|
||||
builder.append(renderFqName(fragment.fqName))
|
||||
builder.append(renderFqName(fragment.fqName.toUnsafe()))
|
||||
if (debugMode) {
|
||||
builder.append(" in ")
|
||||
renderName(fragment.getContainingDeclaration(), builder)
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.kotlin.renderer
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.name.FqNameBase
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
public fun qualifiedNameForSourceCode(descriptor: ClassifierDescriptor): String {
|
||||
@@ -31,7 +31,7 @@ public fun qualifiedNameForSourceCode(descriptor: ClassifierDescriptor): String
|
||||
|
||||
private fun qualifierName(descriptor: DeclarationDescriptor): String? = when (descriptor) {
|
||||
is ClassDescriptor -> qualifiedNameForSourceCode(descriptor)
|
||||
is PackageFragmentDescriptor -> descriptor.fqName.render()
|
||||
is PackageFragmentDescriptor -> descriptor.fqName.toUnsafe().render()
|
||||
else -> null
|
||||
}
|
||||
|
||||
@@ -47,18 +47,18 @@ private fun Name.shouldBeEscaped(): Boolean {
|
||||
return string in KeywordStringsGenerated.KEYWORDS || string.any { !Character.isLetterOrDigit(it) && it != '_' }
|
||||
}
|
||||
|
||||
public fun FqNameBase.render(): String {
|
||||
public fun FqNameUnsafe.render(): String {
|
||||
return renderFqName(pathSegments())
|
||||
}
|
||||
|
||||
public fun renderFqName(pathSegments: List<Name>): String {
|
||||
return StringBuilder {
|
||||
return buildString {
|
||||
for (element in pathSegments) {
|
||||
if (length() > 0) {
|
||||
if (length > 0) {
|
||||
append(".")
|
||||
}
|
||||
append(element.render())
|
||||
}
|
||||
}.toString()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public final class ImportPath {
|
||||
}
|
||||
|
||||
public String getPathStr() {
|
||||
return RenderingUtilsKt.render(fqName) + (isAllUnder ? ".*" : "");
|
||||
return RenderingUtilsKt.render(fqName.toUnsafe()) + (isAllUnder ? ".*" : "");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ open class DeserializedAnnotationsWithPossibleTargets(
|
||||
annotationWithTarget ->
|
||||
if (annotationWithTarget.target != null) return@firstOrNull false
|
||||
val descriptor = annotationWithTarget.annotation.type.constructor.declarationDescriptor
|
||||
descriptor is ClassDescriptor && fqName.equalsTo(DescriptorUtils.getFqName(descriptor))
|
||||
descriptor is ClassDescriptor && fqName.toUnsafe() == DescriptorUtils.getFqName(descriptor)
|
||||
}?.annotation
|
||||
|
||||
override fun findExternalAnnotation(fqName: FqName) = null
|
||||
|
||||
+4
-4
@@ -106,7 +106,7 @@ private fun setupFileStub(fileStub: KotlinFileStubImpl, packageFqName: FqName) {
|
||||
|
||||
fun createStubForPackageName(packageDirectiveStub: KotlinPlaceHolderStubImpl<KtPackageDirective>, packageFqName: FqName) {
|
||||
val segments = packageFqName.pathSegments().toArrayList()
|
||||
val iterator = segments.listIterator(segments.size())
|
||||
val iterator = segments.listIterator(segments.size)
|
||||
|
||||
fun recCreateStubForPackageName(current: StubElement<out PsiElement>) {
|
||||
when (iterator.previousIndex()) {
|
||||
@@ -130,10 +130,10 @@ fun createStubForPackageName(packageDirectiveStub: KotlinPlaceHolderStubImpl<KtP
|
||||
fun createStubForTypeName(typeClassId: ClassId, parent: StubElement<out PsiElement>): KotlinUserTypeStub {
|
||||
val fqName =
|
||||
if (typeClassId.isLocal()) KotlinBuiltIns.FQ_NAMES.any
|
||||
else typeClassId.asSingleFqName()
|
||||
else typeClassId.asSingleFqName().toUnsafe()
|
||||
val segments = fqName.pathSegments().toArrayList()
|
||||
assert(segments.isNotEmpty())
|
||||
val iterator = segments.listIterator(segments.size())
|
||||
val iterator = segments.listIterator(segments.size)
|
||||
|
||||
fun recCreateStubForType(current: StubElement<out PsiElement>): KotlinUserTypeStub {
|
||||
val lastSegment = iterator.previous()
|
||||
@@ -276,7 +276,7 @@ fun createTargetedAnnotationStubs(
|
||||
hasValueArguments = false
|
||||
)
|
||||
if (target != null) {
|
||||
KotlinAnnotationUseSiteTargetStubImpl(annotationEntryStubImpl, StringRef.fromString(target.name())!!)
|
||||
KotlinAnnotationUseSiteTargetStubImpl(annotationEntryStubImpl, StringRef.fromString(target.name)!!)
|
||||
}
|
||||
val constructorCallee = KotlinPlaceHolderStubImpl<KtConstructorCalleeExpression>(annotationEntryStubImpl, KtStubElementTypes.CONSTRUCTOR_CALLEE)
|
||||
val typeReference = KotlinPlaceHolderStubImpl<KtTypeReference>(constructorCallee, KtStubElementTypes.TYPE_REFERENCE)
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.idea.highlighter.renderersUtil
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.renderer.NameShortness
|
||||
import org.jetbrains.kotlin.renderer.RenderingFormat
|
||||
@@ -112,7 +111,7 @@ fun <D : CallableDescriptor> renderResolvedCall(resolvedCall: ResolvedCall<D>):
|
||||
append(" <i>defined in</i> ")
|
||||
val containingDeclaration = resultingDescriptor.getContainingDeclaration()
|
||||
val fqName = DescriptorUtils.getFqName(containingDeclaration)
|
||||
append(if (FqName.ROOT.equalsTo(fqName)) "root package" else fqName.asString())
|
||||
append(if (fqName.isRoot) "root package" else fqName.asString())
|
||||
}
|
||||
return stringBuilder.toString()
|
||||
}
|
||||
|
||||
+2
-2
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.renderer.NameShortness
|
||||
import org.jetbrains.kotlin.renderer.render
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
import javax.swing.Icon
|
||||
|
||||
public open class DescriptorMemberChooserObject(
|
||||
@@ -75,7 +75,7 @@ public open class DescriptorMemberChooserObject(
|
||||
|
||||
public fun getText(descriptor: DeclarationDescriptor): String {
|
||||
return if (descriptor is ClassDescriptor)
|
||||
descriptor.fqNameSafe.render()
|
||||
descriptor.fqNameUnsafe.render()
|
||||
else
|
||||
MEMBER_RENDERER.render(descriptor)
|
||||
}
|
||||
|
||||
@@ -211,10 +211,10 @@ public class KotlinImportOptimizer() : ImportOptimizer {
|
||||
}
|
||||
|
||||
// now check that there are no conflicts and all classes are really imported
|
||||
val fileWithImportsText = StringBuilder {
|
||||
append("package ").append(file.packageFqName.render()).append("\n")
|
||||
importsToGenerate.filter { it.isAllUnder() }.map { "import " + it.pathStr }.joinTo(this, "\n")
|
||||
}.toString()
|
||||
val fileWithImportsText = buildString {
|
||||
append("package ").append(file.packageFqName.toUnsafe().render()).append("\n")
|
||||
importsToGenerate.filter { it.isAllUnder }.map { "import " + it.pathStr }.joinTo(this, "\n")
|
||||
}
|
||||
val fileWithImports = KtPsiFactory(file).createAnalyzableFile("Dummy.kt", fileWithImportsText, file)
|
||||
val scope = fileWithImports.getResolutionFacade().getFileResolutionScope(fileWithImports)
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ import org.jetbrains.kotlin.idea.util.ProjectRootsUtil
|
||||
import org.jetbrains.kotlin.idea.util.string.collapseSpaces
|
||||
import org.jetbrains.kotlin.j2k.ConverterSettings
|
||||
import org.jetbrains.kotlin.j2k.JavaToKotlinConverter
|
||||
import org.jetbrains.kotlin.name.FqNameBase
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.codeFragmentUtil.suppressDiagnosticsInDebugMode
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
@@ -692,7 +692,7 @@ public fun invokeOnceOnCommandFinish(action: () -> Unit) {
|
||||
|
||||
public fun String.quoteIfNeeded(): String = if (KotlinNameSuggester.isIdentifier(this)) this else "`$this`"
|
||||
|
||||
public fun FqNameBase.hasIdentifiersOnly(): Boolean = pathSegments().all { KotlinNameSuggester.isIdentifier(it.asString()) }
|
||||
public fun FqNameUnsafe.hasIdentifiersOnly(): Boolean = pathSegments().all { KotlinNameSuggester.isIdentifier(it.asString()) }
|
||||
|
||||
public fun KtClass.createPrimaryConstructorIfAbsent(): KtPrimaryConstructor {
|
||||
val constructor = getPrimaryConstructor()
|
||||
|
||||
+4
-4
@@ -24,14 +24,14 @@ import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentInt
|
||||
import org.jetbrains.kotlin.psi.KtPackageDirective
|
||||
|
||||
public class ChangePackageToMatchDirectoryIntention : JetSelfTargetingOffsetIndependentIntention<KtPackageDirective>(
|
||||
javaClass(), "", "Change file's package to match directory"
|
||||
KtPackageDirective::class.java, "", "Change file's package to match directory"
|
||||
) {
|
||||
override fun isApplicableTo(element: KtPackageDirective): Boolean {
|
||||
val file = element.getContainingJetFile()
|
||||
if (file.packageMatchesDirectory()) return false
|
||||
|
||||
val fqNameByDirectory = file.getFqNameByDirectory()
|
||||
if (!fqNameByDirectory.hasIdentifiersOnly()) {
|
||||
if (!fqNameByDirectory.toUnsafe().hasIdentifiersOnly()) {
|
||||
if (isIntentionBaseInspectionEnabled(file.project, element)) {
|
||||
text = "File package doesn't match directory"
|
||||
return true
|
||||
@@ -46,7 +46,7 @@ public class ChangePackageToMatchDirectoryIntention : JetSelfTargetingOffsetInde
|
||||
override fun applyTo(element: KtPackageDirective, editor: Editor) {
|
||||
val file = element.getContainingJetFile()
|
||||
val newFqName = file.getFqNameByDirectory()
|
||||
if (!newFqName.hasIdentifiersOnly()) return
|
||||
if (!newFqName.toUnsafe().hasIdentifiersOnly()) return
|
||||
KotlinChangePackageRefactoring(file).run(newFqName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user