Insert import on applying top level function completion
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public final class DescriptorsUtils {
|
||||
|
||||
private DescriptorsUtils() {
|
||||
}
|
||||
|
||||
public static String getFQName(@NotNull NamespaceDescriptor namespaceDescriptor) {
|
||||
|
||||
NamespaceDescriptor tempNamespace = namespaceDescriptor;
|
||||
String fqn = tempNamespace.getName();
|
||||
|
||||
while (tempNamespace.getContainingDeclaration() instanceof NamespaceDescriptor) {
|
||||
tempNamespace = (NamespaceDescriptor) tempNamespace.getContainingDeclaration();
|
||||
|
||||
assert tempNamespace != null;
|
||||
fqn = tempNamespace.getName() + "." + fqn;
|
||||
}
|
||||
|
||||
return fqn;
|
||||
}
|
||||
|
||||
public static String getFQName(@NotNull NamedFunctionDescriptor functionDescriptor) {
|
||||
if (functionDescriptor.getContainingDeclaration() instanceof NamespaceDescriptor) {
|
||||
final String namespaceFQN = getFQName((NamespaceDescriptor) functionDescriptor.getContainingDeclaration());
|
||||
return !namespaceFQN.isEmpty() ? namespaceFQN + "." + functionDescriptor.getName() : functionDescriptor.getName();
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Currently supported only for top level functions");
|
||||
}
|
||||
|
||||
public static boolean isTopLevelFunction(@NotNull NamedFunctionDescriptor functionDescriptor) {
|
||||
return functionDescriptor.getContainingDeclaration() instanceof NamespaceDescriptor;
|
||||
}
|
||||
}
|
||||
@@ -107,17 +107,6 @@ public class JetPsiUtil {
|
||||
}
|
||||
}
|
||||
|
||||
// public static String getFQName(JetNamespace jetNamespace) {
|
||||
// JetNamespace parent = PsiTreeUtil.getParentOfType(jetNamespace, JetNamespace.class);
|
||||
// if (parent != null) {
|
||||
// String parentFQName = getFQName(parent);
|
||||
// if (parentFQName.length() > 0) {
|
||||
// return parentFQName + "." + getFQName(jetNamespace.getNamespaceHeader());
|
||||
// }
|
||||
// }
|
||||
// return getFQName(jetNamespace.getNamespaceHeader()); // TODO: Must include module root namespace
|
||||
// }
|
||||
|
||||
private static String getFQName(JetNamespaceHeader header) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (JetSimpleNameExpression nameExpression : header.getParentNamespaceNames()) {
|
||||
|
||||
@@ -88,11 +88,14 @@ public class AnalyzingUtils {
|
||||
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory,
|
||||
@NotNull BindingTraceContext bindingTraceContext,
|
||||
@NotNull JetSemanticServices semanticServices) {
|
||||
|
||||
JetScope libraryScope = semanticServices.getStandardLibrary().getLibraryScope();
|
||||
ModuleDescriptor owner = new ModuleDescriptor("<module>");
|
||||
|
||||
final WritableScope scope = new WritableScopeImpl(JetScope.EMPTY, owner, new TraceBasedRedeclarationHandler(bindingTraceContext)).setDebugName("Root scope in analyzeNamespace");
|
||||
// configuration.addImports(project, semanticServices, bindingTraceContext, scope);
|
||||
final WritableScope scope = new WritableScopeImpl(
|
||||
JetScope.EMPTY, owner,
|
||||
new TraceBasedRedeclarationHandler(bindingTraceContext)).setDebugName("Root scope in analyzeNamespace");
|
||||
|
||||
scope.importScope(libraryScope);
|
||||
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
|
||||
@@ -136,6 +139,7 @@ public class AnalyzingUtils {
|
||||
throw new IllegalStateException("Must be guaranteed not to happen by the parser");
|
||||
}
|
||||
}, files, filesToAnalyzeCompletely, flowDataTraceFactory, configuration);
|
||||
|
||||
return bindingTraceContext.getBindingContext();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package org.jetbrains.jet.util;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Common methods for working with qualified names strings.
|
||||
*
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public final class QualifiedNamesUtil {
|
||||
|
||||
public static boolean isSubpackageOf(@NotNull final String subpackageName, @NotNull String packageName) {
|
||||
return subpackageName.equals(packageName) ||
|
||||
(subpackageName.startsWith(packageName) && subpackageName.charAt(packageName.length()) == '.');
|
||||
}
|
||||
|
||||
public static boolean isShortNameForFQN(@NotNull final String name, @NotNull final String fqn) {
|
||||
return fqn.equals(name) ||
|
||||
(fqn.endsWith(name) && fqn.charAt(fqn.length() - name.length() - 1) == '.');
|
||||
}
|
||||
|
||||
public static boolean isOneSegmentFQN(@NotNull final String fqn) {
|
||||
if (fqn.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return fqn.indexOf('.') < 0;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String fqnToShortName(@NotNull String fqName) {
|
||||
int lastDotIndex = fqName.lastIndexOf('.');
|
||||
|
||||
if (lastDotIndex != -1) {
|
||||
return fqName.substring(lastDotIndex + 1, fqName.length());
|
||||
}
|
||||
|
||||
return fqName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String withoutLastSegment(@NotNull String fqn) {
|
||||
final int lastDotIndex = fqn.lastIndexOf('.');
|
||||
if (lastDotIndex > 0) {
|
||||
return fqn.substring(0, lastDotIndex);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String combine(@Nullable String first, @NotNull String second) {
|
||||
if (StringUtil.isEmpty(first)) return second;
|
||||
return first + "." + second;
|
||||
}
|
||||
|
||||
// private static String subPackageName(String packageName, String packageFQN) {
|
||||
// if (!isInPackage(packageName, packageFQN)) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// int nextDotIndex = packageFQN.indexOf('.', (packageName + ".").length());
|
||||
//
|
||||
// if (nextDotIndex != -1) {
|
||||
// return packageFQN.substring((packageName + ".").length(), nextDotIndex);
|
||||
// }
|
||||
//
|
||||
// return packageFQN.substring((packageName + ".").length());
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user