Mark deprecated items in ProjectView (class, function, property, class-object)

#KT-2944 Fixed Mark deprecated classes in Project Tree
This commit is contained in:
Natalia.Ukhorskaya
2012-10-19 15:29:31 +04:00
parent 92ff6abf50
commit aa28a03f61
5 changed files with 50 additions and 12 deletions
@@ -185,6 +185,35 @@ public class JetPsiUtil {
return firstPart.child(name); return firstPart.child(name);
} }
@Nullable
public static Name getShortName(JetAnnotationEntry annotation) {
JetTypeReference typeReference = annotation.getTypeReference();
assert typeReference != null : "Annotation entry hasn't typeReference " + annotation.getText();
JetTypeElement typeElement = typeReference.getTypeElement();
if (typeElement instanceof JetUserType) {
JetUserType userType = (JetUserType) typeElement;
String shortName = userType.getReferencedName();
if (shortName != null) {
return Name.identifier(shortName);
}
}
return null;
}
public static boolean isDeprecated(JetModifierListOwner owner) {
JetModifierList modifierList = owner.getModifierList();
if (modifierList != null) {
List<JetAnnotationEntry> annotationEntries = modifierList.getAnnotationEntries();
for (JetAnnotationEntry annotation : annotationEntries) {
Name shortName = getShortName(annotation);
if (KotlinBuiltIns.getInstance().getDeprecatedAnnotation().getName().equals(shortName)) {
return true;
}
}
}
return false;
}
@Nullable @IfNotParsed @Nullable @IfNotParsed
public static ImportPath getImportPath(JetImportDirective importDirective) { public static ImportPath getImportPath(JetImportDirective importDirective) {
final JetExpression importedReference = importDirective.getImportedReference(); final JetExpression importedReference = importDirective.getImportedReference();
@@ -27,6 +27,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.psi.stubs.PsiJetAnnotationStub; import org.jetbrains.jet.lang.psi.stubs.PsiJetAnnotationStub;
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetAnnotationStubImpl; import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetAnnotationStubImpl;
import org.jetbrains.jet.lang.resolve.name.Name;
import java.io.IOException; import java.io.IOException;
@@ -48,18 +49,9 @@ public class JetAnnotationElementType extends JetStubElementType<PsiJetAnnotatio
@Override @Override
public PsiJetAnnotationStub createStub(@NotNull JetAnnotationEntry psi, StubElement parentStub) { public PsiJetAnnotationStub createStub(@NotNull JetAnnotationEntry psi, StubElement parentStub) {
JetTypeReference typeReference = psi.getTypeReference(); Name shortName = JetPsiUtil.getShortName(psi);
assert typeReference != null : "Annotation entry hasn't typeReference " + psi.getText(); String resultName = shortName != null ? shortName.getName() : psi.getText();
JetTypeElement typeElement = typeReference.getTypeElement(); return new PsiJetAnnotationStubImpl(parentStub, JetStubElementTypes.ANNOTATION_ENTRY, resultName);
String shortName = null;
if (typeElement instanceof JetUserType) {
JetUserType userType = (JetUserType) typeElement;
shortName = userType.getReferencedName();
}
if (shortName == null) {
shortName = psi.getText();
}
return new PsiJetAnnotationStubImpl(parentStub, JetStubElementTypes.ANNOTATION_ENTRY, shortName);
} }
@Override @Override
@@ -23,6 +23,7 @@ import com.intellij.ide.util.treeView.AbstractTreeNode;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import org.jetbrains.jet.lang.psi.JetClassObject; import org.jetbrains.jet.lang.psi.JetClassObject;
import org.jetbrains.jet.lang.psi.JetPsiUtil;
import java.util.Collection; import java.util.Collection;
@@ -60,4 +61,9 @@ public class JetClassObjectTreeNode extends AbstractPsiBasedNode<JetClassObject>
return super.canRepresent(element) || canRepresentPsiElement(getValue(), element, getSettings()); return super.canRepresent(element) || canRepresentPsiElement(getValue(), element, getSettings());
} }
@Override
protected boolean isDeprecated() {
return JetPsiUtil.isDeprecated(getValue());
}
} }
@@ -25,6 +25,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import org.jetbrains.jet.lang.psi.JetClassOrObject; import org.jetbrains.jet.lang.psi.JetClassOrObject;
import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetPsiUtil;
import org.jetbrains.jet.plugin.JetIconProvider; import org.jetbrains.jet.plugin.JetIconProvider;
import java.util.Collection; import java.util.Collection;
@@ -75,6 +76,11 @@ public class JetClassOrObjectTreeNode extends AbstractPsiBasedNode<JetClassOrObj
} }
} }
@Override
protected boolean isDeprecated() {
return JetPsiUtil.isDeprecated(getValue());
}
@Override @Override
public boolean canRepresent(Object element) { public boolean canRepresent(Object element) {
if (!isValid()) { if (!isValid()) {
@@ -105,4 +105,9 @@ public class JetDeclarationTreeNode extends AbstractPsiBasedNode<JetDeclaration>
data.setPresentableText(text); data.setPresentableText(text);
} }
} }
@Override
protected boolean isDeprecated() {
return JetPsiUtil.isDeprecated(getValue());
}
} }