KT-1666 Invoking "Go to Declaration" for String type offers two variants - Temp boring fix

#KT-1666 fixed
This commit is contained in:
Nikolay Krasko
2012-04-08 20:38:11 +04:00
parent 89b08d6296
commit 4ec080f71f
4 changed files with 26 additions and 14 deletions
@@ -24,6 +24,7 @@ import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
import org.jetbrains.jet.lang.descriptors.VariableAsFunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
/**
* @author abreslav
@@ -39,7 +40,18 @@ public class BindingContextUtils {
if (declarationDescriptor == null) {
return bindingContext.get(BindingContext.LABEL_TARGET, referenceExpression);
}
return bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, declarationDescriptor);
PsiElement element = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, declarationDescriptor);
if (element != null) {
return element;
}
// TODO: Need to have a valid stubs for standard classes
if (referenceExpression != null && JetStandardClasses.getAllStandardClasses().contains(declarationDescriptor)) {
return referenceExpression.getContainingFile();
}
return null;
}
@Nullable
@@ -0,0 +1 @@
~file~var x : `file`String = ""
@@ -156,11 +156,18 @@ public abstract class ExpectedResolveData {
Position position = entry.getValue();
PsiElement element = position.getElement();
PsiElement ancestorOfType = getAncestorOfType(JetDeclaration.class, element);
if (ancestorOfType == null) {
JetNamespaceHeader header = getAncestorOfType(JetNamespaceHeader.class, element);
assert header != null : "Not a declaration: " + name;
ancestorOfType = element;
PsiElement ancestorOfType;
if (name.equals("file")) {
ancestorOfType = element.getContainingFile();
}
else {
ancestorOfType = getAncestorOfType(JetDeclaration.class, element);
if (ancestorOfType == null) {
JetNamespaceHeader header = getAncestorOfType(JetNamespaceHeader.class, element);
assert header != null : "Not a declaration: " + name;
ancestorOfType = element;
}
}
nameToDeclaration.put(name, ancestorOfType);
declarationToName.put(ancestorOfType, name);
@@ -17,7 +17,6 @@
package org.jetbrains.jet.plugin.references;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementResolveResult;
import com.intellij.psi.PsiPolyVariantReference;
@@ -111,13 +110,6 @@ public abstract class JetPsiReference implements PsiPolyVariantReference {
Collection<? extends DeclarationDescriptor> declarationDescriptors = bindingContext.get(AMBIGUOUS_REFERENCE_TARGET, myExpression);
if (declarationDescriptors != null) return null;
VirtualFile elementFile = file.getVirtualFile();
if (elementFile != null && elementFile.getNameWithoutExtension().equals(getElement().getText())) {
LOG.warn("Possible problem with file rename: " + elementFile.getNameWithoutExtension() +
", element: " + getElement());
}
// TODO: Need a better resolution for Intrinsic function (KT-975)
return file;
}