Advanced way for getting package fqn from psi
This commit is contained in:
@@ -24,6 +24,7 @@ import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.JetNodeTypes;
|
import org.jetbrains.jet.JetNodeTypes;
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -89,9 +90,30 @@ public class JetNamespaceHeader extends JetReferenceExpression {
|
|||||||
return getName().length() == 0;
|
return getName().length() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public FqName getFqName() {
|
||||||
|
String qualifiedName = getQualifiedName();
|
||||||
|
return qualifiedName.isEmpty() ? FqName.ROOT : new FqName(qualifiedName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public FqName getParentFqName(JetReferenceExpression nameExpression) {
|
||||||
|
String parentQualifiedName = getQualifiedNameParentOf(nameExpression);
|
||||||
|
return parentQualifiedName.isEmpty() ? FqName.ROOT : new FqName(parentQualifiedName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public String getQualifiedName() {
|
public String getQualifiedName() {
|
||||||
|
return getQualifiedNameParentOf(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getQualifiedNameParentOf(@Nullable JetReferenceExpression nameExpression) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
for (JetSimpleNameExpression e : findChildrenByClass(JetSimpleNameExpression.class)) {
|
for (JetSimpleNameExpression e : findChildrenByClass(JetSimpleNameExpression.class)) {
|
||||||
|
if (e == nameExpression) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (builder.length() > 0) {
|
if (builder.length() > 0) {
|
||||||
builder.append(".");
|
builder.append(".");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,16 +97,6 @@ public class JetPsiUtil {
|
|||||||
return rootElements;
|
return rootElements;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static JetNamedFunction getSurroundingFunction(@Nullable PsiElement element) {
|
|
||||||
while (element != null) {
|
|
||||||
if (element instanceof JetNamedFunction) return (JetNamedFunction) element;
|
|
||||||
if (element instanceof JetClassOrObject || element instanceof JetFile) return null;
|
|
||||||
element = element.getParent();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static String unquoteIdentifier(@NotNull String quoted) {
|
public static String unquoteIdentifier(@NotNull String quoted) {
|
||||||
if (quoted.indexOf('`') < 0) {
|
if (quoted.indexOf('`') < 0) {
|
||||||
@@ -135,23 +125,9 @@ public class JetPsiUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static FqName getFQName(JetNamespaceHeader header) {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
for (JetSimpleNameExpression nameExpression : header.getParentNamespaceNames()) {
|
|
||||||
builder.append(nameExpression.getReferencedName());
|
|
||||||
builder.append(".");
|
|
||||||
}
|
|
||||||
builder.append(header.getName());
|
|
||||||
return new FqName(builder.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static FqName getFQName(JetFile file) {
|
public static FqName getFQName(JetFile file) {
|
||||||
if (file.isScript()) {
|
JetNamespaceHeader header = file.getNamespaceHeader();
|
||||||
return FqName.ROOT;
|
return header != null ? header.getFqName() : FqName.ROOT;
|
||||||
}
|
|
||||||
else {
|
|
||||||
return getFQName(file.getNamespaceHeader());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -202,11 +178,6 @@ public class JetPsiUtil {
|
|||||||
return new ImportPath(text.replaceAll(" ", "") + (importDirective.isAllUnder() ? ".*" : ""));
|
return new ImportPath(text.replaceAll(" ", "") + (importDirective.isAllUnder() ? ".*" : ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private static FqName makeFQName(@NotNull FqName prefix, @NotNull JetClassOrObject jetClass) {
|
|
||||||
return prefix.child(Name.identifier(jetClass.getName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isIrrefutable(JetWhenEntry entry) {
|
public static boolean isIrrefutable(JetWhenEntry entry) {
|
||||||
if (entry.isElse()) return true;
|
if (entry.isElse()) return true;
|
||||||
for (JetWhenCondition condition : entry.getConditions()) {
|
for (JetWhenCondition condition : entry.getConditions()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user