Correct class object mapping in kotlin => java run
This commit is contained in:
@@ -196,20 +196,10 @@ public class JetTypeMapper {
|
||||
}
|
||||
}
|
||||
|
||||
private static String getLocalNameForObject(JetObjectDeclaration object) {
|
||||
public static String getLocalNameForObject(JetObjectDeclaration object) {
|
||||
PsiElement parent = object.getParent();
|
||||
if (parent instanceof JetObjectLiteralExpression) {
|
||||
PsiElement expressionParent = parent.getParent();
|
||||
|
||||
if (expressionParent instanceof JetProperty) {
|
||||
JetProperty property = (JetProperty) expressionParent;
|
||||
if (property.getInitializer() == parent) {
|
||||
return property.getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (parent instanceof JetClassObject) {
|
||||
return "$ClassObject";
|
||||
if (parent instanceof JetClassObject) {
|
||||
return "ClassObject$";
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.intellij.psi.impl.file.PsiPackageImpl;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.codegen.JetTypeMapper;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
|
||||
@@ -73,14 +74,11 @@ public class JavaElementFinder extends PsiElementFinder {
|
||||
final String packageName = JetPsiUtil.getFQName(rootNamespace);
|
||||
if (packageName != null && qualifiedName.startsWith(packageName)) {
|
||||
if (qualifiedName.equals(fqn(packageName, "namespace"))) {
|
||||
answer.add(new JetLightClass(psiManager, file, "namespace"));
|
||||
answer.add(new JetLightClass(psiManager, file, qualifiedName));
|
||||
}
|
||||
|
||||
for (JetDeclaration declaration : rootNamespace.getDeclarations()) {
|
||||
if (declaration instanceof JetClassOrObject) {
|
||||
if (qualifiedName.equals(fqn(packageName, declaration.getName()))) {
|
||||
answer.add(new JetLightClass(psiManager, file, declaration.getName()));
|
||||
}
|
||||
else {
|
||||
for (JetDeclaration declaration : rootNamespace.getDeclarations()) {
|
||||
scanClasses(answer, declaration, qualifiedName, packageName, file);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,6 +86,36 @@ public class JavaElementFinder extends PsiElementFinder {
|
||||
return answer.toArray(new PsiClass[answer.size()]);
|
||||
}
|
||||
|
||||
private void scanClasses(List<PsiClass> answer, JetDeclaration declaration, String qualifiedName, String containerFqn, JetFile file) {
|
||||
if (declaration instanceof JetClassOrObject) {
|
||||
String localName = getLocalName(declaration);
|
||||
if (localName != null) {
|
||||
String fqn = fqn(containerFqn, localName);
|
||||
if (qualifiedName.equals(fqn)) {
|
||||
answer.add(new JetLightClass(psiManager, file, qualifiedName));
|
||||
}
|
||||
else {
|
||||
for (JetDeclaration child : ((JetClassOrObject) declaration).getDeclarations()) {
|
||||
scanClasses(answer, child, qualifiedName, fqn, file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (declaration instanceof JetClassObject) {
|
||||
scanClasses(answer, ((JetClassObject) declaration).getObjectDeclaration(), qualifiedName, containerFqn, file);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getLocalName(JetDeclaration declaration) {
|
||||
String given = declaration.getName();
|
||||
if (given != null) return given;
|
||||
|
||||
if (declaration instanceof JetObjectDeclaration) {
|
||||
return JetTypeMapper.getLocalNameForObject((JetObjectDeclaration) declaration);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getClassNames(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) {
|
||||
Set<String> answer = new HashSet<String>();
|
||||
@@ -99,7 +127,7 @@ public class JavaElementFinder extends PsiElementFinder {
|
||||
answer.add("namespace");
|
||||
for (JetDeclaration declaration : rootNamespace.getDeclarations()) {
|
||||
if (declaration instanceof JetClassOrObject) {
|
||||
answer.add(declaration.getName());
|
||||
answer.add(getLocalName(declaration));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,10 +163,10 @@ public class JavaElementFinder extends PsiElementFinder {
|
||||
for (JetFile file : filesInScope) {
|
||||
final JetNamespace rootNamespace = file.getRootNamespace();
|
||||
if (packageFQN.equals(JetPsiUtil.getFQName(rootNamespace))) {
|
||||
answer.add(new JetLightClass(psiManager, file, "namespace"));
|
||||
answer.add(new JetLightClass(psiManager, file, fqn(packageFQN, "namespace")));
|
||||
for (JetDeclaration declaration : rootNamespace.getDeclarations()) {
|
||||
if (declaration instanceof JetClassOrObject) {
|
||||
answer.add(new JetLightClass(psiManager, file, declaration.getName()));
|
||||
answer.add(new JetLightClass(psiManager, file, fqn(packageFQN, getLocalName(declaration))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ package org.jetbrains.jet.plugin.java;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.PsiManagerImpl;
|
||||
@@ -40,40 +41,49 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa
|
||||
private final static Key<CachedValue<PsiJavaFileStub>> JAVA_API_STUB = Key.create("JAVA_API_STUB");
|
||||
|
||||
private final JetFile file;
|
||||
private final String className;
|
||||
private final String qualifiedName;
|
||||
private PsiClass delegate;
|
||||
|
||||
public JetLightClass(PsiManager manager, JetFile file, String className) {
|
||||
public JetLightClass(PsiManager manager, JetFile file, String qualifiedName) {
|
||||
super(manager, JetLanguage.INSTANCE);
|
||||
this.file = file;
|
||||
this.className = className;
|
||||
this.qualifiedName = qualifiedName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return className;
|
||||
int idx = qualifiedName.lastIndexOf('.');
|
||||
return idx > 0 ? qualifiedName.substring(idx + 1) : qualifiedName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement copy() {
|
||||
return new JetLightClass(getManager(), file, className);
|
||||
return new JetLightClass(getManager(), file, qualifiedName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiFile getContainingFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiClass getDelegate() {
|
||||
if (delegate == null) {
|
||||
delegate = findClass(className, getStub());
|
||||
delegate = findClass(qualifiedName, getStub());
|
||||
if (delegate == null) {
|
||||
delegate = findClass(qualifiedName, getStub());
|
||||
}
|
||||
}
|
||||
return delegate;
|
||||
}
|
||||
|
||||
private static PsiClass findClass(String name, StubElement<?> stub) {
|
||||
if (stub instanceof PsiClassStub && name.equals(((PsiClassStub) stub).getName())) {
|
||||
private static PsiClass findClass(String fqn, StubElement<?> stub) {
|
||||
if (stub instanceof PsiClassStub && Comparing.equal(fqn, ((PsiClassStub) stub).getQualifiedName())) {
|
||||
return (PsiClass) stub.getPsi();
|
||||
}
|
||||
|
||||
for (StubElement child : stub.getChildrenStubs()) {
|
||||
PsiClass answer = findClass(name, child);
|
||||
PsiClass answer = findClass(fqn, child);
|
||||
if (answer != null) return answer;
|
||||
}
|
||||
|
||||
@@ -82,8 +92,7 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa
|
||||
|
||||
@Override
|
||||
public String getQualifiedName() {
|
||||
String fqName = JetPsiUtil.getFQName(file.getRootNamespace());
|
||||
return fqName.length() == 0 ? className : fqName + "." + className;
|
||||
return qualifiedName;
|
||||
}
|
||||
|
||||
private PsiJavaFileStub getStub() {
|
||||
@@ -163,4 +172,8 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa
|
||||
return answer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEquivalentTo(PsiElement another) {
|
||||
return another instanceof PsiClass && Comparing.equal(((PsiClass) another).getQualifiedName(), getQualifiedName());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user