Don't add import if there's general import with .* exist

This commit is contained in:
Nikolay Krasko
2012-02-08 15:27:41 +04:00
parent e8ffaa28f3
commit 01e71cbd59
8 changed files with 80 additions and 2 deletions
@@ -138,6 +138,17 @@ public class JetPsiUtil {
return jetClass.getName();
}
@Nullable @JetElement.IfNotParsed
public static String getImportPath(JetImportDirective importDirective) {
final JetExpression importedReference = importDirective.getImportedReference();
if (importedReference == null) {
return null;
}
final String text = importedReference.getText();
return text.replaceAll(" ", "") + (importDirective.isAllUnder() ? ".*" : "");
}
private static String makeFQName(String prefix, JetClassOrObject jetClass) {
return ((prefix == null || prefix.length() == 0) ? "" : prefix + ".") + jetClass.getName();
}
@@ -100,4 +100,19 @@ public final class QualifiedNamesUtil {
return null;
}
/**
* Check that given fqn could be imported with import.
*
* @param importPath path from the import. Could contain .* part
* @param fqn
* @return
*/
public static boolean isImported(@NotNull String importPath, @NotNull String fqn) {
if (importPath.endsWith("*")) {
return withoutLastSegment(importPath).equals(withoutLastSegment(fqn));
}
return importPath.equals(fqn);
}
}