Rewrite utils method for qualified names to Kotlin
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
* Copyright 2010-2014 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.
|
||||
@@ -26,8 +26,8 @@ import org.jetbrains.jet.lang.descriptors.PackageViewDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetNamed;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.name.NamePackage;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.util.QualifiedNamesUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -80,7 +80,7 @@ public class ResolveSessionUtils {
|
||||
while (true) {
|
||||
PackageViewDescriptor packageDescriptor = analyzer.getModuleDescriptor().getPackage(packageFqName);
|
||||
if (packageDescriptor != null) {
|
||||
FqName classInPackagePath = new FqName(QualifiedNamesUtil.tail(packageFqName, fqName));
|
||||
FqName classInPackagePath = NamePackage.tail(fqName, packageFqName);
|
||||
Collection<ClassDescriptor> descriptors = getClassOrObjectDescriptorsByFqName(packageDescriptor, classInPackagePath, filter);
|
||||
classDescriptors.addAll(descriptors);
|
||||
}
|
||||
|
||||
+3
-3
@@ -33,7 +33,7 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.storage.MemoizedFunctionToNullable;
|
||||
import org.jetbrains.jet.storage.NotNullLazyValue;
|
||||
import org.jetbrains.jet.storage.StorageManager;
|
||||
import org.jetbrains.jet.util.QualifiedNamesUtil;
|
||||
import org.jetbrains.jet.lang.resolve.name.NamePackage;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -110,12 +110,12 @@ public class FileBasedDeclarationProviderFactory implements DeclarationProviderF
|
||||
|
||||
Collection<NavigatablePsiElement> resultElements = Lists.newArrayList();
|
||||
for (FqName declaredPackage : index.invoke().filesByPackage.keys()) {
|
||||
if (QualifiedNamesUtil.isSubpackageOf(declaredPackage, fqName)) {
|
||||
if (NamePackage.isSubpackageOf(declaredPackage, fqName)) {
|
||||
Collection<JetFile> files = index.invoke().filesByPackage.get(declaredPackage);
|
||||
resultElements.addAll(ContainerUtil.map(files, new Function<JetFile, NavigatablePsiElement>() {
|
||||
@Override
|
||||
public NavigatablePsiElement fun(JetFile file) {
|
||||
return JetPsiUtil.getPackageReference(file, QualifiedNamesUtil.numberOfSegments(fqName) - 1);
|
||||
return JetPsiUtil.getPackageReference(file, NamePackage.numberOfSegments(fqName) - 1);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -1,202 +0,0 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
/**
|
||||
* Common methods for working with qualified names.
|
||||
*/
|
||||
public final class QualifiedNamesUtil {
|
||||
|
||||
private QualifiedNamesUtil() {
|
||||
}
|
||||
|
||||
public static boolean isSubpackageOf(@NotNull FqName subpackageName, @NotNull FqName packageName) {
|
||||
if (subpackageName.equals(packageName)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (packageName.isRoot()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String subpackageNameStr = subpackageName.asString();
|
||||
String packageNameStr = packageName.asString();
|
||||
|
||||
return isSubpackageOf(subpackageNameStr, packageNameStr);
|
||||
}
|
||||
|
||||
public static boolean isOneSegmentFQN(@NotNull String fqn) {
|
||||
if (fqn.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return fqn.indexOf('.') < 0;
|
||||
}
|
||||
|
||||
public static boolean isOneSegmentFQN(@NotNull FqName fqn) {
|
||||
return isOneSegmentFQN(fqn.asString());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getFirstSegment(@NotNull String fqn) {
|
||||
int dotIndex = fqn.indexOf('.');
|
||||
return (dotIndex != -1) ? fqn.substring(0, dotIndex) : fqn;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static FqName withoutLastSegment(@NotNull FqName fqName) {
|
||||
return fqName.parent();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static FqName withoutFirstSegment(@NotNull FqName fqName) {
|
||||
if (fqName.isRoot() || fqName.parent().isRoot()) {
|
||||
return FqName.ROOT;
|
||||
}
|
||||
|
||||
String fqNameStr = fqName.asString();
|
||||
return new FqName(fqNameStr.substring(fqNameStr.indexOf('.'), fqNameStr.length()));
|
||||
}
|
||||
|
||||
public static int numberOfSegments(@NotNull FqName fqName) {
|
||||
if (fqName.isRoot()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1 + numberOfSegments(fqName.parent());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static FqName combine(@NotNull FqName first, @NotNull Name second) {
|
||||
return first.child(second);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tail part of the full fqn by subtracting head part.
|
||||
*
|
||||
* @param headFQN
|
||||
* @param fullFQN
|
||||
* @return tail fqn. If first part is not a begging of the full fqn, fullFQN will be returned.
|
||||
*/
|
||||
@NotNull
|
||||
public static String tail(@NotNull FqName headFQN, @NotNull FqName fullFQN) {
|
||||
if (!isSubpackageOf(fullFQN, headFQN) || headFQN.isRoot()) {
|
||||
return fullFQN.asString();
|
||||
}
|
||||
|
||||
return fullFQN.equals(headFQN) ?
|
||||
"" :
|
||||
fullFQN.asString().substring(headFQN.asString().length() + 1); // (headFQN + '.').length
|
||||
}
|
||||
|
||||
/**
|
||||
* Add one segment of nesting to given qualified name according to the full qualified name.
|
||||
*
|
||||
* @param fqn
|
||||
* @param fullFQN
|
||||
* @return qualified name with one more segment or null if fqn is not head part of fullFQN or there's no additional segment.
|
||||
*/
|
||||
@Nullable
|
||||
public static FqName plusOneSegment(@NotNull FqName fqn, @NotNull FqName fullFQN) {
|
||||
if (!isSubpackageOf(fullFQN, fqn)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String nextSegment = getFirstSegment(tail(fqn, fullFQN));
|
||||
|
||||
if (isOneSegmentFQN(nextSegment)) {
|
||||
return combine(fqn, Name.guess(nextSegment));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isImported(@NotNull ImportPath alreadyImported, @NotNull FqName fqName) {
|
||||
if (alreadyImported.hasAlias()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (alreadyImported.isAllUnder() && !fqName.isRoot()) {
|
||||
return alreadyImported.fqnPart().equals(fqName.parent());
|
||||
}
|
||||
|
||||
return alreadyImported.fqnPart().equals(fqName);
|
||||
}
|
||||
|
||||
public static boolean isImported(@NotNull ImportPath alreadyImported, @NotNull ImportPath newImport) {
|
||||
if (newImport.isAllUnder() || newImport.hasAlias()) {
|
||||
return alreadyImported.equals(newImport);
|
||||
}
|
||||
|
||||
return isImported(alreadyImported, newImport.fqnPart());
|
||||
}
|
||||
|
||||
public static boolean isImported(@NotNull Iterable<ImportPath> imports, @NotNull ImportPath newImport) {
|
||||
for (ImportPath alreadyImported : imports) {
|
||||
if (isImported(alreadyImported, newImport)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isValidJavaFqName(@Nullable String qualifiedName) {
|
||||
if (qualifiedName == null) return false;
|
||||
|
||||
// Check that it is javaName(\.javaName)* or an empty string
|
||||
|
||||
class State {}
|
||||
State BEGINNING = new State();
|
||||
State MIDDLE = new State();
|
||||
State AFTER_DOT = new State();
|
||||
|
||||
State state = BEGINNING;
|
||||
|
||||
int length = qualifiedName.length();
|
||||
for (int i = 0; i < length; i++) {
|
||||
char c = qualifiedName.charAt(i);
|
||||
if (state == BEGINNING || state == AFTER_DOT) {
|
||||
if (!Character.isJavaIdentifierPart(c)) return false;
|
||||
state = MIDDLE;
|
||||
}
|
||||
|
||||
//noinspection ConstantConditions
|
||||
assert state == MIDDLE;
|
||||
|
||||
if (c == '.') {
|
||||
state = AFTER_DOT;
|
||||
}
|
||||
else if (!Character.isJavaIdentifierPart(c)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return state != AFTER_DOT;
|
||||
}
|
||||
|
||||
public static boolean isSubpackageOf(String subpackageNameStr, String packageNameStr) {
|
||||
return subpackageNameStr.equals(packageNameStr) ||
|
||||
(subpackageNameStr.startsWith(packageNameStr) && subpackageNameStr.charAt(packageNameStr.length()) == '.');
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
* Copyright 2010-2014 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.
|
||||
@@ -41,7 +41,7 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaPsiFacadeKotlinHacks;
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.util.QualifiedNamesUtil;
|
||||
import org.jetbrains.jet.lang.resolve.name.NamePackage;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -110,7 +110,7 @@ public class JavaElementFinder extends PsiElementFinder implements JavaPsiFacade
|
||||
}
|
||||
|
||||
private PsiClass[] doFindClasses(String qualifiedNameString, GlobalSearchScope scope) {
|
||||
if (!QualifiedNamesUtil.isValidJavaFqName(qualifiedNameString)) {
|
||||
if (!NamePackage.isValidJavaFqName(qualifiedNameString)) {
|
||||
return PsiClass.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ public class JavaElementFinder extends PsiElementFinder implements JavaPsiFacade
|
||||
|
||||
@Override
|
||||
public PsiPackage findPackage(@NotNull String qualifiedNameString) {
|
||||
if (!QualifiedNamesUtil.isValidJavaFqName(qualifiedNameString)) {
|
||||
if (!NamePackage.isValidJavaFqName(qualifiedNameString)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
* Copyright 2010-2014 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.
|
||||
@@ -20,7 +20,7 @@ import com.google.common.collect.Lists;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.util.QualifiedNamesUtil;
|
||||
import org.jetbrains.jet.lang.resolve.name.NamePackage;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -104,22 +104,22 @@ public class FqNameTest {
|
||||
|
||||
@Test
|
||||
public void isValidJavaFqName() {
|
||||
Assert.assertTrue(QualifiedNamesUtil.isValidJavaFqName(""));
|
||||
Assert.assertTrue(QualifiedNamesUtil.isValidJavaFqName("a"));
|
||||
Assert.assertTrue(QualifiedNamesUtil.isValidJavaFqName("1"));
|
||||
Assert.assertTrue(QualifiedNamesUtil.isValidJavaFqName("a.a"));
|
||||
Assert.assertTrue(QualifiedNamesUtil.isValidJavaFqName("org.jetbrains"));
|
||||
Assert.assertTrue(QualifiedNamesUtil.isValidJavaFqName("$"));
|
||||
Assert.assertTrue(QualifiedNamesUtil.isValidJavaFqName("org.A$B"));
|
||||
Assert.assertTrue(NamePackage.isValidJavaFqName(""));
|
||||
Assert.assertTrue(NamePackage.isValidJavaFqName("a"));
|
||||
Assert.assertTrue(NamePackage.isValidJavaFqName("1"));
|
||||
Assert.assertTrue(NamePackage.isValidJavaFqName("a.a"));
|
||||
Assert.assertTrue(NamePackage.isValidJavaFqName("org.jetbrains"));
|
||||
Assert.assertTrue(NamePackage.isValidJavaFqName("$"));
|
||||
Assert.assertTrue(NamePackage.isValidJavaFqName("org.A$B"));
|
||||
|
||||
Assert.assertFalse(QualifiedNamesUtil.isValidJavaFqName("."));
|
||||
Assert.assertFalse(QualifiedNamesUtil.isValidJavaFqName(".."));
|
||||
Assert.assertFalse(QualifiedNamesUtil.isValidJavaFqName("a."));
|
||||
Assert.assertFalse(QualifiedNamesUtil.isValidJavaFqName(".a"));
|
||||
Assert.assertFalse(QualifiedNamesUtil.isValidJavaFqName("a..b"));
|
||||
Assert.assertFalse(QualifiedNamesUtil.isValidJavaFqName("a.b.."));
|
||||
Assert.assertFalse(QualifiedNamesUtil.isValidJavaFqName("a.b."));
|
||||
Assert.assertFalse(QualifiedNamesUtil.isValidJavaFqName("a.b...)"));
|
||||
Assert.assertFalse(QualifiedNamesUtil.isValidJavaFqName("a.b.<special>"));
|
||||
Assert.assertFalse(NamePackage.isValidJavaFqName("."));
|
||||
Assert.assertFalse(NamePackage.isValidJavaFqName(".."));
|
||||
Assert.assertFalse(NamePackage.isValidJavaFqName("a."));
|
||||
Assert.assertFalse(NamePackage.isValidJavaFqName(".a"));
|
||||
Assert.assertFalse(NamePackage.isValidJavaFqName("a..b"));
|
||||
Assert.assertFalse(NamePackage.isValidJavaFqName("a.b.."));
|
||||
Assert.assertFalse(NamePackage.isValidJavaFqName("a.b."));
|
||||
Assert.assertFalse(NamePackage.isValidJavaFqName("a.b...)"));
|
||||
Assert.assertFalse(NamePackage.isValidJavaFqName("a.b.<special>"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
* Copyright 2010-2014 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.
|
||||
@@ -108,7 +108,7 @@ public final class FqNameUnsafe extends FqNameBase {
|
||||
}
|
||||
|
||||
public boolean isRoot() {
|
||||
return fqName.equals("");
|
||||
return fqName.isEmpty();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.name
|
||||
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath
|
||||
|
||||
public fun FqName.isSubpackageOf(packageName: FqName): Boolean {
|
||||
return when {
|
||||
this == packageName -> true
|
||||
packageName.isRoot() -> true
|
||||
else -> isSubpackageOf(this.asString(), packageName.asString())
|
||||
}
|
||||
}
|
||||
|
||||
public fun FqName.isParent(child: FqName): Boolean = child.isSubpackageOf(this)
|
||||
|
||||
public fun FqName.isOneSegmentFQN(): Boolean = !isRoot() && parent().isRoot()
|
||||
|
||||
public fun FqName.withoutFirstSegment(): FqName {
|
||||
if (isRoot() || parent().isRoot()) return FqName.ROOT
|
||||
|
||||
val fqNameStr = asString()
|
||||
return FqName(fqNameStr.substring(fqNameStr.indexOf('.'), fqNameStr.length()))
|
||||
}
|
||||
|
||||
public fun FqName.numberOfSegments(): Int {
|
||||
return if (isRoot()) 0 else 1 + parent().numberOfSegments()
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tail part of the full fqn by subtracting head part.
|
||||
*
|
||||
* @param headFQN
|
||||
* @return tail fqn. If first part is not a begging of the full fqn, fullFQN will be returned.
|
||||
*/
|
||||
public fun FqName.tail(headFQN: FqName): FqName {
|
||||
return when {
|
||||
!isSubpackageOf(headFQN) || headFQN.isRoot() -> this
|
||||
this == headFQN -> FqName.ROOT
|
||||
else -> FqName(asString().substring(headFQN.asString().length + 1))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add one segment of nesting to given qualified name according to the full qualified name.
|
||||
*
|
||||
* @param fullFQN
|
||||
* @return qualified name with one more segment or null if fqn is not head part of fullFQN or there's no additional segment.
|
||||
*/
|
||||
public fun FqName.plusOneSegment(fullFQN: FqName): FqName? {
|
||||
if (!isParent(fullFQN) || fullFQN == this) return null
|
||||
|
||||
return child(fullFQN.tail(this).pathSegments().first!!)
|
||||
}
|
||||
|
||||
public fun FqName.isImported(importPath: ImportPath): Boolean {
|
||||
return when {
|
||||
importPath.hasAlias() -> false
|
||||
importPath.isAllUnder() && !isRoot() -> importPath.fqnPart() == this.parent()
|
||||
else -> importPath.fqnPart() == this
|
||||
}
|
||||
}
|
||||
|
||||
public fun ImportPath.isImported(alreadyImported: ImportPath): Boolean {
|
||||
return if (isAllUnder() || hasAlias()) this == alreadyImported else fqnPart().isImported(alreadyImported)
|
||||
}
|
||||
|
||||
public fun ImportPath.isImported(imports: Iterable<ImportPath>): Boolean = imports.any { isImported(it) }
|
||||
|
||||
public fun isValidJavaFqName(qualifiedName: String?): Boolean {
|
||||
if (qualifiedName == null) return false
|
||||
|
||||
// Check that it is javaName(\.javaName)* or an empty string
|
||||
enum class State {
|
||||
BEGINNING
|
||||
MIDDLE
|
||||
AFTER_DOT
|
||||
}
|
||||
|
||||
var state = State.BEGINNING
|
||||
|
||||
for (c in qualifiedName) {
|
||||
when (state) {
|
||||
State.BEGINNING, State.AFTER_DOT -> {
|
||||
if (!Character.isJavaIdentifierPart(c)) return false
|
||||
state = State.MIDDLE
|
||||
}
|
||||
State.MIDDLE -> {
|
||||
if (c == '.') {
|
||||
state = State.AFTER_DOT
|
||||
}
|
||||
else if (!Character.isJavaIdentifierPart(c)) return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return state != State.AFTER_DOT
|
||||
}
|
||||
|
||||
private fun isSubpackageOf(subpackageNameStr: String, packageNameStr: String): Boolean {
|
||||
return subpackageNameStr == packageNameStr ||
|
||||
(subpackageNameStr.startsWith(packageNameStr) && subpackageNameStr[packageNameStr.length()] == '.')
|
||||
}
|
||||
|
||||
private fun getFirstSegment(fqn: String): String {
|
||||
val dotIndex = fqn.indexOf('.')
|
||||
return if ((dotIndex != -1)) fqn.substring(0, dotIndex) else fqn
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
* Copyright 2010-2014 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.
|
||||
@@ -34,7 +34,6 @@ import org.jetbrains.jet.lang.resolve.kotlin.VirtualFileFinder;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassHeader;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.util.QualifiedNamesUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -145,8 +144,7 @@ public class JetFromJavaDescriptorHelper {
|
||||
FqName classFQN = new FqName(qualifiedName);
|
||||
|
||||
if (JavaResolverPsiUtils.isCompiledKotlinPackageClass(containingClass)) {
|
||||
FqName classParentFQN = QualifiedNamesUtil.withoutLastSegment(classFQN);
|
||||
return QualifiedNamesUtil.combine(classParentFQN, Name.identifier(method.getName()));
|
||||
return classFQN.parent().child(Name.identifier(method.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
* Copyright 2010-2014 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.
|
||||
@@ -32,7 +32,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.asJava.KotlinLightClassForExplicitDeclaration;
|
||||
import org.jetbrains.jet.asJava.LightClassConstructionContext;
|
||||
import org.jetbrains.jet.asJava.LightClassGenerationSupport;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PackageViewDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||
@@ -40,13 +43,13 @@ import org.jetbrains.jet.lang.resolve.lazy.ForceResolveUtil;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.KotlinCodeAnalyzer;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.name.NamePackage;
|
||||
import org.jetbrains.jet.plugin.libraries.JetSourceNavigationHelper;
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
|
||||
import org.jetbrains.jet.plugin.project.ResolveSessionForBodies;
|
||||
import org.jetbrains.jet.plugin.stubindex.JetAllPackagesIndex;
|
||||
import org.jetbrains.jet.plugin.stubindex.JetClassByPackageIndex;
|
||||
import org.jetbrains.jet.plugin.stubindex.JetFullClassNameIndex;
|
||||
import org.jetbrains.jet.util.QualifiedNamesUtil;
|
||||
import org.jetbrains.jet.utils.Profiler;
|
||||
|
||||
import java.util.*;
|
||||
@@ -231,10 +234,10 @@ public class IDELightClassGenerationSupport extends LightClassGenerationSupport
|
||||
for (JetFile file : files) {
|
||||
FqName fqName = JetPsiUtil.getFQName(file);
|
||||
|
||||
assert QualifiedNamesUtil.isSubpackageOf(fqName, fqn) : "Registered package is not a subpackage of actually declared package:\n" +
|
||||
"in index: " + fqn + "\n" +
|
||||
"declared: " + fqName;
|
||||
FqName subpackage = QualifiedNamesUtil.plusOneSegment(fqn, fqName);
|
||||
assert NamePackage.isSubpackageOf(fqName, fqn) : "Registered package is not a subpackage of actually declared package:\n" +
|
||||
"in index: " + fqn + "\n" +
|
||||
"declared: " + fqName;
|
||||
FqName subpackage = NamePackage.plusOneSegment(fqn, fqName);
|
||||
if (subpackage != null) {
|
||||
result.add(subpackage);
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
* Copyright 2010-2014 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.
|
||||
@@ -26,9 +26,9 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||
import org.jetbrains.jet.lang.resolve.name.NamePackage;
|
||||
import org.jetbrains.jet.plugin.completion.JetLookupObject;
|
||||
import org.jetbrains.jet.plugin.quickfix.ImportInsertHelper;
|
||||
import org.jetbrains.jet.util.QualifiedNamesUtil;
|
||||
|
||||
public class JetDeclarationRemotenessWeigher extends LookupElementWeigher {
|
||||
private final JetFile file;
|
||||
@@ -65,7 +65,7 @@ public class JetDeclarationRemotenessWeigher extends LookupElementWeigher {
|
||||
if (descriptor != null) {
|
||||
FqNameUnsafe fqName = DescriptorUtils.getFqName(descriptor);
|
||||
// Invalid name can be met for class object descriptor: Test.MyTest.A.<no name provided>.testOther
|
||||
if (QualifiedNamesUtil.isValidJavaFqName(fqName.toString())) {
|
||||
if (NamePackage.isValidJavaFqName(fqName.toString())) {
|
||||
ImportPath importPath = new ImportPath(fqName.toString());
|
||||
if (ImportInsertHelper.needImport(importPath, file)) {
|
||||
return MyResult.notImported;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
* Copyright 2010-2014 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.
|
||||
@@ -35,7 +35,7 @@ import org.jetbrains.jet.lang.resolve.java.JavaResolverPsiUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
|
||||
import org.jetbrains.jet.util.QualifiedNamesUtil;
|
||||
import org.jetbrains.jet.lang.resolve.name.NamePackage;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -96,7 +96,7 @@ public class JetImportOptimizer implements ImportOptimizer {
|
||||
}
|
||||
|
||||
for (FqName usedName : usedNames) {
|
||||
if (QualifiedNamesUtil.isImported(importPath, usedName)) {
|
||||
if (NamePackage.isImported(usedName, importPath)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -207,7 +207,7 @@ public class JetImportOptimizer implements ImportOptimizer {
|
||||
if (fqName == null) {
|
||||
fqName = new FqName(referencedName.asString());
|
||||
} else {
|
||||
fqName = QualifiedNamesUtil.combine(fqName, referencedName);
|
||||
fqName = fqName.child(referencedName);
|
||||
}
|
||||
if (nameExpression.equals(element)) {
|
||||
return fqName;
|
||||
@@ -266,10 +266,10 @@ public class JetImportOptimizer implements ImportOptimizer {
|
||||
return null;
|
||||
}
|
||||
if (JavaResolverPsiUtils.isCompiledKotlinPackageClass(containingClass)) {
|
||||
return QualifiedNamesUtil.combine(classFQN.parent(), Name.identifier(memberName));
|
||||
return classFQN.parent().child(Name.identifier(memberName));
|
||||
}
|
||||
else {
|
||||
return QualifiedNamesUtil.combine(classFQN, Name.identifier(memberName));
|
||||
return classFQN.child(Name.identifier(memberName));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
* Copyright 2010-2014 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.
|
||||
@@ -26,7 +26,6 @@ import org.jetbrains.jet.lang.psi.JetParameter;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeReference;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.util.QualifiedNamesUtil;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -65,7 +64,7 @@ public class JetFunctionPresenter implements ItemPresentationProvider<JetNamedFu
|
||||
if (name != null) {
|
||||
JetTypeReference receiverTypeRef = function.getReceiverTypeRef();
|
||||
String extensionLocation = receiverTypeRef != null ? "for " + receiverTypeRef.getText() + " " : "";
|
||||
return String.format("(%sin %s)", extensionLocation, QualifiedNamesUtil.withoutLastSegment(name));
|
||||
return String.format("(%sin %s)", extensionLocation, name.parent());
|
||||
}
|
||||
|
||||
return "";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
* Copyright 2010-2014 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.
|
||||
@@ -29,7 +29,7 @@ import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.plugin.project.ProjectStructureUtil;
|
||||
import org.jetbrains.jet.plugin.references.JetReference;
|
||||
import org.jetbrains.jet.util.QualifiedNamesUtil;
|
||||
import org.jetbrains.jet.lang.resolve.name.NamePackage;
|
||||
import org.jetbrains.k2js.analyze.AnalyzerFacadeForJS;
|
||||
|
||||
import java.util.List;
|
||||
@@ -122,7 +122,7 @@ public class ImportInsertHelper {
|
||||
|
||||
if (!importPath.isAllUnder() && !importPath.hasAlias()) {
|
||||
// Single element import without .* and alias is useless
|
||||
if (QualifiedNamesUtil.isOneSegmentFQN(importPath.fqnPart())) {
|
||||
if (NamePackage.isOneSegmentFQN(importPath.fqnPart())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ public class ImportInsertHelper {
|
||||
List<ImportPath> defaultImports = ProjectStructureUtil.isJsKotlinModule(contextFile)
|
||||
? AnalyzerFacadeForJS.DEFAULT_IMPORTS
|
||||
: AnalyzerFacadeForJVM.DEFAULT_IMPORTS;
|
||||
return QualifiedNamesUtil.isImported(defaultImports, importPath);
|
||||
return NamePackage.isImported(importPath, defaultImports);
|
||||
}
|
||||
|
||||
public static boolean needImport(@NotNull FqName fqName, @NotNull JetFile file) {
|
||||
@@ -152,7 +152,7 @@ public class ImportInsertHelper {
|
||||
|
||||
public static boolean needImport(@NotNull ImportPath importPath, @NotNull JetFile file, List<JetImportDirective> importDirectives) {
|
||||
if (importPath.fqnPart().firstSegmentIs(JavaDescriptorResolver.JAVA_ROOT)) {
|
||||
FqName withoutJavaRoot = QualifiedNamesUtil.withoutFirstSegment(importPath.fqnPart());
|
||||
FqName withoutJavaRoot = NamePackage.withoutFirstSegment(importPath.fqnPart());
|
||||
importPath = new ImportPath(withoutJavaRoot, importPath.isAllUnder(), importPath.getAlias());
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ public class ImportInsertHelper {
|
||||
// Check if import is already present
|
||||
for (JetImportDirective directive : importDirectives) {
|
||||
ImportPath existentImportPath = JetPsiUtil.getImportPath(directive);
|
||||
if (existentImportPath != null && QualifiedNamesUtil.isImported(existentImportPath, importPath)) {
|
||||
if (existentImportPath != null && NamePackage.isImported(importPath, existentImportPath)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
* Copyright 2010-2014 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.
|
||||
@@ -32,7 +32,7 @@ import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.plugin.stubindex.JetAllPackagesIndex;
|
||||
import org.jetbrains.jet.plugin.stubindex.JetTopLevelFunctionsFqnNameIndex;
|
||||
import org.jetbrains.jet.plugin.stubindex.JetTopLevelPropertiesFqnNameIndex;
|
||||
import org.jetbrains.jet.util.QualifiedNamesUtil;
|
||||
import org.jetbrains.jet.lang.resolve.name.NamePackage;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -86,7 +86,7 @@ public class StubPackageMemberDeclarationProvider extends AbstractStubDeclaratio
|
||||
return ContainerUtil.map(files, new Function<JetFile, NavigatablePsiElement>() {
|
||||
@Override
|
||||
public NavigatablePsiElement fun(JetFile file) {
|
||||
return JetPsiUtil.getPackageReference(file, QualifiedNamesUtil.numberOfSegments(fqName) - 1);
|
||||
return JetPsiUtil.getPackageReference(file, NamePackage.numberOfSegments(fqName) - 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
* Copyright 2010-2014 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.
|
||||
@@ -25,8 +25,8 @@ import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.NamePackage;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.util.QualifiedNamesUtil;
|
||||
|
||||
public class JetPsiHeuristicsUtil {
|
||||
private JetPsiHeuristicsUtil() {}
|
||||
@@ -48,7 +48,8 @@ public class JetPsiHeuristicsUtil {
|
||||
JetFile targetFile = (JetFile) classOrObject.getContainingFile();
|
||||
FqName targetPackage = JetPsiUtil.getFQName(targetFile);
|
||||
FqName fromPackage = JetPsiUtil.getFQName(fromFile);
|
||||
return QualifiedNamesUtil.isSubpackageOf(fromPackage, targetPackage);
|
||||
|
||||
return NamePackage.isSubpackageOf(fromPackage, targetPackage);
|
||||
}
|
||||
}
|
||||
return member.hasModifierProperty(PsiModifier.PUBLIC) || member.hasModifierProperty(PsiModifier.PROTECTED);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
* Copyright 2010-2014 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.
|
||||
@@ -20,8 +20,8 @@ import com.intellij.psi.PsiImportStatementBase
|
||||
import org.jetbrains.jet.j2k.*
|
||||
import com.intellij.psi.PsiImportList
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName
|
||||
import org.jetbrains.jet.util.QualifiedNamesUtil
|
||||
import org.jetbrains.jet.lang.resolve.java.mapping.JavaToKotlinClassMap
|
||||
import org.jetbrains.jet.lang.resolve.name.isValidJavaFqName
|
||||
|
||||
|
||||
class Import(val name: String) : Element {
|
||||
@@ -33,7 +33,7 @@ class ImportList(val imports: List<Import>) : Element {
|
||||
!it.name.isEmpty() && it.name !in NOT_NULL_ANNOTATIONS
|
||||
}.filter {
|
||||
// If name is invalid, like with star imports, don't try to filter
|
||||
if (!QualifiedNamesUtil.isValidJavaFqName(it.name))
|
||||
if (!isValidJavaFqName(it.name))
|
||||
true
|
||||
else {
|
||||
// If imported class has a kotlin analog, drop the import
|
||||
|
||||
Reference in New Issue
Block a user