Parents checked and fixed
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiNameIdentifierOwner;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -27,6 +30,58 @@ public abstract class JetNamedDeclaration extends JetDeclaration implements PsiN
|
||||
return findChildByType(JetTokens.IDENTIFIER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiReference getReference() {
|
||||
return new PsiReference() {
|
||||
@Override
|
||||
public PsiElement getElement() {
|
||||
return getNameIdentifier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextRange getRangeInElement() {
|
||||
return getElement().getTextRange().shiftRight(getElement().getTextOffset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement resolve() {
|
||||
return PsiTreeUtil.getParentOfType(JetNamedDeclaration.this, JetFile.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getCanonicalText() {
|
||||
return "<TBD>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
|
||||
throw new IncorrectOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
|
||||
throw new IncorrectOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReferenceTo(PsiElement element) {
|
||||
return resolve() == element;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Object[] getVariants() {
|
||||
return EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSoft() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
|
||||
return getNameIdentifier().replace(JetChangeUtil.createNameIdentifier(getProject(), name));
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaPackageScope;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaSemanticServices;
|
||||
import org.jetbrains.jet.lang.types.ModuleDescriptor;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -26,7 +27,7 @@ public class AnalyzingUtils {
|
||||
JavaSemanticServices javaSemanticServices = new JavaSemanticServices(project, semanticServices, bindingTraceContext);
|
||||
|
||||
JetScope libraryScope = semanticServices.getStandardLibrary().getLibraryScope();
|
||||
WritableScope scope = new WritableScope(libraryScope, libraryScope.getContainingDeclaration());
|
||||
WritableScope scope = new WritableScope(libraryScope, new ModuleDescriptor("<module>"));
|
||||
// scope.importScope(javaSemanticServices.getDescriptorResolver().resolveNamespace("").getMemberScope());
|
||||
// scope.importScope(javaSemanticServices.getDescriptorResolver().resolveNamespace("java.lang").getMemberScope());
|
||||
scope.importScope(new JavaPackageScope("", null, javaSemanticServices));
|
||||
|
||||
@@ -14,6 +14,8 @@ public interface BindingContext {
|
||||
FunctionDescriptor getFunctionDescriptor(JetFunction declaration);
|
||||
PropertyDescriptor getPropertyDescriptor(JetProperty declaration);
|
||||
|
||||
DeclarationDescriptor getDeclarationDescriptor(JetDeclaration declaration);
|
||||
|
||||
Type getExpressionType(JetExpression expression);
|
||||
|
||||
JetScope getTopLevelScope();
|
||||
|
||||
@@ -48,6 +48,12 @@ public class BindingTraceContext extends BindingTrace implements BindingContext
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@Override
|
||||
public DeclarationDescriptor getDeclarationDescriptor(JetDeclaration declaration) {
|
||||
return declarationsToDescriptors.get(declaration);
|
||||
}
|
||||
|
||||
public NamespaceDescriptor getNamespaceDescriptor(JetNamespace declaration) {
|
||||
return (NamespaceDescriptor) declarationsToDescriptors.get(declaration);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
||||
private final WritableScope unsubstitutedMemberScope;
|
||||
private TypeConstructor typeConstructor;
|
||||
|
||||
public MutableClassDescriptor(@NotNull JetScope outerScope) {
|
||||
public MutableClassDescriptor(@NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope outerScope) {
|
||||
super(containingDeclaration);
|
||||
this.unsubstitutedMemberScope = new WritableScope(outerScope, this);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.types.Attribute;
|
||||
import org.jetbrains.jet.lang.types.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.types.DeclarationDescriptorVisitor;
|
||||
@@ -13,7 +12,11 @@ import java.util.List;
|
||||
*/
|
||||
public abstract class MutableDeclarationDescriptor implements DeclarationDescriptor {
|
||||
private String name;
|
||||
private DeclarationDescriptor containingDeclaration;
|
||||
private final DeclarationDescriptor containingDeclaration;
|
||||
|
||||
public MutableDeclarationDescriptor(DeclarationDescriptor containingDeclaration) {
|
||||
this.containingDeclaration = containingDeclaration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Attribute> getAttributes() {
|
||||
@@ -35,16 +38,11 @@ public abstract class MutableDeclarationDescriptor implements DeclarationDescrip
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getContainingDeclaration() {
|
||||
return containingDeclaration;
|
||||
}
|
||||
|
||||
public void setContainingDeclaration(@Nullable DeclarationDescriptor containingDeclaration) {
|
||||
this.containingDeclaration = containingDeclaration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptVoid(DeclarationDescriptorVisitor<Void, Void> visitor) {
|
||||
accept(visitor, null);
|
||||
|
||||
@@ -58,7 +58,7 @@ public class TopDownAnalyzer {
|
||||
List<JetImportDirective> importDirectives = namespace.getImportDirectives();
|
||||
|
||||
String name = namespace.getName();
|
||||
NamespaceDescriptor namespaceDescriptor = declaringScope.getNamespace(name);
|
||||
NamespaceDescriptor namespaceDescriptor = declaringScope.getDeclaredNamespace(name);
|
||||
if (namespaceDescriptor == null) {
|
||||
namespaceDescriptor = new NamespaceDescriptor(
|
||||
declaringScope.getContainingDeclaration(),
|
||||
@@ -104,7 +104,7 @@ public class TopDownAnalyzer {
|
||||
}
|
||||
|
||||
private WritableScope processClass(@NotNull WritableScope declaringScope, JetClass klass) {
|
||||
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(declaringScope);
|
||||
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(declaringScope.getContainingDeclaration(), declaringScope);
|
||||
mutableClassDescriptor.setName(klass.getName());
|
||||
|
||||
declaringScope.addClassDescriptor(mutableClassDescriptor);
|
||||
|
||||
@@ -216,10 +216,16 @@ public class WritableScope extends JetScopeAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespaceDescriptor getNamespace(@NotNull String name) {
|
||||
public NamespaceDescriptor getDeclaredNamespace(@NotNull String name) {
|
||||
NamespaceDescriptor namespaceDescriptor = getNamespaceDescriptors().get(name);
|
||||
if (namespaceDescriptor != null) return namespaceDescriptor;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespaceDescriptor getNamespace(@NotNull String name) {
|
||||
NamespaceDescriptor declaredNamespace = getDeclaredNamespace(name);
|
||||
if (declaredNamespace != null) return declaredNamespace;
|
||||
|
||||
NamespaceDescriptor namespace = super.getNamespace(name);
|
||||
if (namespace != null) return namespace;
|
||||
|
||||
@@ -25,7 +25,6 @@ public class JavaTypeTransformer {
|
||||
|
||||
@NotNull
|
||||
public Type transform(PsiType javaType) {
|
||||
System.out.println("javaType = " + javaType.getInternalCanonicalText());
|
||||
return javaType.accept(new PsiTypeVisitor<Type>() {
|
||||
@Override
|
||||
public Type visitClassType(PsiClassType classType) {
|
||||
|
||||
@@ -31,7 +31,6 @@ public abstract class DeclarationDescriptorImpl extends AnnotatedImpl implements
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getContainingDeclaration() {
|
||||
return containingDeclaration;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.jetbrains.jet.lang.types;
|
||||
|
||||
import org.jetbrains.jet.lang.resolve.LazySubstitutingClassDescriptor;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
@@ -25,4 +23,8 @@ public class DeclarationDescriptorVisitor<R, D> {
|
||||
public R visitClassDescriptor(ClassDescriptor descriptor, D data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public R visitModuleDeclaration(ModuleDescriptor moduleDescriptor, D data) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.jetbrains.jet.lang.types;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class ModuleDescriptor extends DeclarationDescriptorImpl {
|
||||
public ModuleDescriptor(String name) {
|
||||
super(null, Collections.<Attribute>emptyList(), name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitModuleDeclaration(this, data);
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,13 @@ import com.intellij.lang.documentation.QuickDocumentationProvider;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.jet.lang.ErrorHandler;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.types.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.resolve.DescriptorUtil;
|
||||
|
||||
/**
|
||||
@@ -29,14 +31,27 @@ public class JetQuickDocumentationProvider extends QuickDocumentationProvider {
|
||||
BindingContext bindingContext = AnalyzingUtils.analyzeFile((JetFile) element.getContainingFile(), ErrorHandler.DO_NOTHING);
|
||||
DeclarationDescriptor declarationDescriptor = bindingContext.resolveReferenceExpression(ref);
|
||||
if (declarationDescriptor != null) {
|
||||
String text = DescriptorUtil.renderPresentableText(declarationDescriptor);
|
||||
text = text.replaceAll("<", "<");
|
||||
return text;
|
||||
return render(declarationDescriptor);
|
||||
}
|
||||
return "Unresolved";
|
||||
}
|
||||
|
||||
// if (originalElement.getNode().getElementType() == JetTokens.IDENTIFIER) {
|
||||
// JetDeclaration declaration = PsiTreeUtil.getParentOfType(originalElement, JetDeclaration.class);
|
||||
// BindingContext bindingContext = AnalyzingUtils.analyzeFile((JetFile) element.getContainingFile(), ErrorHandler.DO_NOTHING);
|
||||
// DeclarationDescriptor declarationDescriptor = bindingContext.getDeclarationDescriptor(declaration);
|
||||
// if (declarationDescriptor != null) {
|
||||
// return render(declarationDescriptor);
|
||||
// }
|
||||
// }
|
||||
return "Not a reference";
|
||||
}
|
||||
|
||||
private String render(DeclarationDescriptor declarationDescriptor) {
|
||||
String text = DescriptorUtil.renderPresentableText(declarationDescriptor);
|
||||
text = text.replaceAll("<", "<");
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -16,13 +16,13 @@ public class DescriptorUtil {
|
||||
@Override
|
||||
public Void visitPropertyDescriptor(PropertyDescriptor descriptor, StringBuilder builder) {
|
||||
Type type = descriptor.getType();
|
||||
builder.append(descriptor.getName()).append(" : ").append(type);
|
||||
builder.append(renderName(descriptor)).append(" : ").append(type);
|
||||
return super.visitPropertyDescriptor(descriptor, builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitFunctionDescriptor(FunctionDescriptor descriptor, StringBuilder builder) {
|
||||
builder.append("fun ").append(descriptor.getName());
|
||||
builder.append("fun ").append(renderName(descriptor));
|
||||
List<TypeParameterDescriptor> typeParameters = descriptor.getTypeParameters();
|
||||
renderTypeParameters(typeParameters, builder);
|
||||
builder.append("(");
|
||||
@@ -61,13 +61,13 @@ public class DescriptorUtil {
|
||||
|
||||
@Override
|
||||
public Void visitNamespaceDescriptor(NamespaceDescriptor namespaceDescriptor, StringBuilder builder) {
|
||||
builder.append("namespace ").append(namespaceDescriptor.getName());
|
||||
builder.append("namespace ").append(renderName(namespaceDescriptor));
|
||||
return super.visitNamespaceDescriptor(namespaceDescriptor, builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitClassDescriptor(ClassDescriptor descriptor, StringBuilder builder) {
|
||||
builder.append("class ").append(descriptor.getName());
|
||||
builder.append("class ").append(renderName(descriptor));
|
||||
renderTypeParameters(descriptor.getTypeConstructor().getParameters(), builder);
|
||||
return super.visitClassDescriptor(descriptor, builder);
|
||||
}
|
||||
@@ -76,8 +76,23 @@ public class DescriptorUtil {
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
private static StringBuilder renderName(DeclarationDescriptor descriptor) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
renderName(descriptor, stringBuilder);
|
||||
return stringBuilder;
|
||||
}
|
||||
|
||||
private static void renderName(DeclarationDescriptor descriptor, StringBuilder stringBuilder) {
|
||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||
if (containingDeclaration != null) {
|
||||
renderName(containingDeclaration, stringBuilder);
|
||||
stringBuilder.append("::");
|
||||
}
|
||||
stringBuilder.append(descriptor.getName());
|
||||
}
|
||||
|
||||
private static void renderTypeParameter(TypeParameterDescriptor descriptor, StringBuilder builder) {
|
||||
builder.append(descriptor.getName());
|
||||
builder.append(renderName(descriptor));
|
||||
if (!descriptor.getUpperBounds().isEmpty()) {
|
||||
Type bound = descriptor.getUpperBounds().iterator().next();
|
||||
if (bound != JetStandardClasses.getAnyType()) {
|
||||
|
||||
Reference in New Issue
Block a user