structure view is in general working
This commit is contained in:
@@ -22,11 +22,13 @@
|
||||
<lang.braceMatcher language="jet" implementationClass="org.jetbrains.jet.lang.JetPairMatcher"/>
|
||||
<lang.parserDefinition language="jet" implementationClass="org.jetbrains.jet.lang.parsing.JetParserDefinition"/>
|
||||
<lang.commenter language="jet" implementationClass="org.jetbrains.jet.plugin.JetCommenter"/>
|
||||
<lang.psiStructureViewFactory language="jet" implementationClass="org.jetbrains.jet.plugin.structureView.JetStructureViewFactory"/>
|
||||
<annotator language="jet" implementationClass="org.jetbrains.jet.lang.annotations.SoftKeywordsAnnotator"/>
|
||||
<annotator language="jet" implementationClass="org.jetbrains.jet.lang.annotations.LabelsAnnotator"/>
|
||||
<annotator language="jet" implementationClass="org.jetbrains.jet.lang.annotations.JetPsiChecker"/>
|
||||
<documentationProvider implementation="org.jetbrains.jet.plugin.JetQuickDocumentationProvider"/>
|
||||
<configurationType implementation="org.jetbrains.jet.run.JetRunConfigurationType"/>
|
||||
<codeInsight.lineMarkerProvider language="jet" implementationClass="org.jetbrains.jet.lang.annotations.JetLineMarkerProvider"/>
|
||||
<iconProvider implementation="org.jetbrains.jet.plugin.JetIconProvider"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
|
||||
@@ -11,19 +11,20 @@ import com.intellij.ide.util.DefaultPsiElementCellRenderer;
|
||||
import com.intellij.openapi.ui.popup.JBPopup;
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.openapi.util.Iconable;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtilBase;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.Icons;
|
||||
import com.intellij.util.PsiIconUtil;
|
||||
import com.intellij.util.PsiNavigateUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -38,7 +39,6 @@ import java.util.Set;
|
||||
public class JetLineMarkerProvider implements LineMarkerProvider {
|
||||
|
||||
public static final Icon OVERRIDING_FUNCTION = IconLoader.getIcon("/general/overridingMethod.png");
|
||||
public static final Icon ICON_FOR_OBJECT = Icons.ANONYMOUS_CLASS_ICON;
|
||||
|
||||
@Override
|
||||
public LineMarkerInfo getLineMarkerInfo(PsiElement element) {
|
||||
@@ -49,47 +49,16 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
|
||||
|
||||
if (element instanceof JetClass) {
|
||||
JetClass jetClass = (JetClass) element;
|
||||
Icon icon = jetClass.hasModifier(JetTokens.ENUM_KEYWORD) ? Icons.ENUM_ICON : Icons.CLASS_ICON;
|
||||
if (jetClass instanceof JetEnumEntry) {
|
||||
JetEnumEntry enumEntry = (JetEnumEntry) jetClass;
|
||||
if (enumEntry.getPrimaryConstructorParameterList() == null) {
|
||||
icon = ICON_FOR_OBJECT;
|
||||
}
|
||||
}
|
||||
return new LineMarkerInfo<JetClass>(jetClass, jetClass.getTextOffset(), icon, Pass.UPDATE_ALL,
|
||||
new Function<JetClass, String>() {
|
||||
@Override
|
||||
public String fun(JetClass jetClass) {
|
||||
ClassDescriptor classDescriptor = bindingContext.getClassDescriptor(jetClass);
|
||||
if (classDescriptor == null) {
|
||||
return "<it>Unresolved</it>";
|
||||
}
|
||||
return DescriptorRenderer.HTML.render(classDescriptor);
|
||||
}
|
||||
},
|
||||
new GutterIconNavigationHandler<JetClass>() {
|
||||
@Override
|
||||
public void navigate(MouseEvent e, JetClass elt) {
|
||||
}
|
||||
});
|
||||
ClassDescriptor classDescriptor = bindingContext.getClassDescriptor(jetClass);
|
||||
String text = classDescriptor == null ? "<i>Unresolved</i>" : DescriptorRenderer.HTML.render(classDescriptor);
|
||||
return createLineMarkerInfo(jetClass, text);
|
||||
}
|
||||
|
||||
if (element instanceof JetProperty) {
|
||||
JetProperty jetProperty = (JetProperty) element;
|
||||
final VariableDescriptor variableDescriptor = bindingContext.getVariableDescriptor(jetProperty);
|
||||
if (variableDescriptor instanceof PropertyDescriptor) {
|
||||
return new LineMarkerInfo<JetProperty>(jetProperty, jetProperty.getTextOffset(), Icons.PROPERTY_ICON, Pass.UPDATE_ALL,
|
||||
new Function<JetProperty, String>() {
|
||||
@Override
|
||||
public String fun(JetProperty property) {
|
||||
return DescriptorRenderer.HTML.render(variableDescriptor);
|
||||
}
|
||||
},
|
||||
new GutterIconNavigationHandler<JetProperty>() {
|
||||
@Override
|
||||
public void navigate(MouseEvent e, JetProperty elt) {
|
||||
}
|
||||
});
|
||||
return createLineMarkerInfo(element, DescriptorRenderer.HTML.render(variableDescriptor));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,22 +133,8 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
|
||||
}
|
||||
|
||||
if (element instanceof JetNamespace) {
|
||||
JetNamespace jetNamespace = (JetNamespace) element;
|
||||
return new LineMarkerInfo<JetNamespace>(
|
||||
jetNamespace, jetNamespace.getTextOffset(), Icons.PACKAGE_ICON, Pass.UPDATE_ALL,
|
||||
new Function<JetNamespace, String>() {
|
||||
@Override
|
||||
public String fun(JetNamespace jetNamespace) {
|
||||
NamespaceDescriptor namespaceDescriptor = bindingContext.getNamespaceDescriptor(jetNamespace);
|
||||
return DescriptorRenderer.HTML.render(namespaceDescriptor);
|
||||
}
|
||||
},
|
||||
new GutterIconNavigationHandler<JetNamespace>() {
|
||||
@Override
|
||||
public void navigate(MouseEvent e, JetNamespace elt) {
|
||||
}
|
||||
}
|
||||
);
|
||||
return createLineMarkerInfo((JetNamespace) element,
|
||||
DescriptorRenderer.HTML.render(bindingContext.getNamespaceDescriptor((JetNamespace) element)));
|
||||
}
|
||||
|
||||
if (element instanceof JetObjectDeclaration && !(element.getParent() instanceof JetExpression)) {
|
||||
@@ -208,6 +163,23 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
|
||||
return null;
|
||||
}
|
||||
|
||||
private <T extends PsiElement> LineMarkerInfo<T> createLineMarkerInfo(T element, final String text) {
|
||||
return new LineMarkerInfo<T>(
|
||||
element, element.getTextOffset(), PsiIconUtil.getProvidersIcon(element, Iconable.ICON_FLAG_CLOSED), Pass.UPDATE_ALL,
|
||||
new Function<T, String>() {
|
||||
@Override
|
||||
public String fun(T jetNamespace) {
|
||||
return text;
|
||||
}
|
||||
},
|
||||
new GutterIconNavigationHandler<T>() {
|
||||
@Override
|
||||
public void navigate(MouseEvent e, T elt) {
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private boolean isMember(@NotNull FunctionDescriptor functionDescriptor) {
|
||||
return functionDescriptor.getContainingDeclaration().getOriginal() instanceof ClassifierDescriptor;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package org.jetbrains.jet.plugin;
|
||||
|
||||
import com.intellij.ide.IconProvider;
|
||||
import com.intellij.openapi.util.Iconable;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.Icons;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class JetIconProvider extends IconProvider {
|
||||
public static final Icon ICON_FOR_OBJECT = Icons.ANONYMOUS_CLASS_ICON;
|
||||
|
||||
@Override
|
||||
public Icon getIcon(@NotNull PsiElement psiElement, int flags) {
|
||||
if (psiElement instanceof JetNamespace) {
|
||||
return (flags & Iconable.ICON_FLAG_OPEN) != 0 ? Icons.PACKAGE_OPEN_ICON : Icons.PACKAGE_ICON;
|
||||
}
|
||||
if (psiElement instanceof JetFunction) {
|
||||
return PsiTreeUtil.getParentOfType(psiElement, JetNamedDeclaration.class) instanceof JetClass
|
||||
? Icons.METHOD_ICON
|
||||
: Icons.FUNCTION_ICON;
|
||||
}
|
||||
if (psiElement instanceof JetClass) {
|
||||
JetClass jetClass = (JetClass) psiElement;
|
||||
Icon icon = jetClass.hasModifier(JetTokens.ENUM_KEYWORD) ? Icons.ENUM_ICON : Icons.CLASS_ICON;
|
||||
if (jetClass instanceof JetEnumEntry) {
|
||||
JetEnumEntry enumEntry = (JetEnumEntry) jetClass;
|
||||
if (enumEntry.getPrimaryConstructorParameterList() == null) {
|
||||
icon = ICON_FOR_OBJECT;
|
||||
}
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
if (psiElement instanceof JetParameter) {
|
||||
if (((JetParameter) psiElement).getValOrVarNode() != null) {
|
||||
JetParameterList parameterList = PsiTreeUtil.getParentOfType(psiElement, JetParameterList.class);
|
||||
if (parameterList != null && parameterList.getParent() instanceof JetClass) {
|
||||
return Icons.PROPERTY_ICON;
|
||||
}
|
||||
}
|
||||
return Icons.PARAMETER_ICON;
|
||||
}
|
||||
if (psiElement instanceof JetProperty) {
|
||||
return Icons.PROPERTY_ICON;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,14 @@ import com.intellij.ide.util.treeView.smartTree.TreeElement;
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import com.intellij.openapi.util.Iconable;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.NavigatablePsiElement;
|
||||
import com.intellij.util.PsiIconUtil;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
@@ -44,7 +49,13 @@ public class JetStructureViewElement implements StructureViewTreeElement {
|
||||
return new ItemPresentation() {
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
return "";
|
||||
String name = myElement.getName();
|
||||
if (StringUtil.isEmpty(name)) {
|
||||
if (myElement instanceof JetClassInitializer) {
|
||||
return "<class initializer>";
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,7 +65,7 @@ public class JetStructureViewElement implements StructureViewTreeElement {
|
||||
|
||||
@Override
|
||||
public Icon getIcon(boolean open) {
|
||||
return myElement.getIcon(open ? Iconable.ICON_FLAG_OPEN : Iconable.ICON_FLAG_CLOSED);
|
||||
return PsiIconUtil.getProvidersIcon(myElement, open ? Iconable.ICON_FLAG_OPEN : Iconable.ICON_FLAG_CLOSED);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,6 +77,36 @@ public class JetStructureViewElement implements StructureViewTreeElement {
|
||||
|
||||
@Override
|
||||
public TreeElement[] getChildren() {
|
||||
return new TreeElement[0]; //To change body of implemented methods use File | Settings | File Templates.
|
||||
if (myElement instanceof JetFile) {
|
||||
JetNamespace rootNamespace = ((JetFile) myElement).getRootNamespace();
|
||||
return new TreeElement[] { new JetStructureViewElement((rootNamespace)) };
|
||||
}
|
||||
else if (myElement instanceof JetNamespace) {
|
||||
return wrapDeclarations(((JetNamespace) myElement).getDeclarations());
|
||||
}
|
||||
else if (myElement instanceof JetClass) {
|
||||
JetClass jetClass = (JetClass) myElement;
|
||||
List<JetDeclaration> declarations = new ArrayList<JetDeclaration>();
|
||||
for (JetParameter parameter : jetClass.getPrimaryConstructorParameters()) {
|
||||
if (parameter.getValOrVarNode() != null) {
|
||||
declarations.add(parameter);
|
||||
}
|
||||
}
|
||||
declarations.addAll(jetClass.getDeclarations());
|
||||
return wrapDeclarations(declarations);
|
||||
|
||||
}
|
||||
else if (myElement instanceof JetClassOrObject) {
|
||||
return wrapDeclarations(((JetClassOrObject) myElement).getDeclarations());
|
||||
}
|
||||
return new TreeElement[0];
|
||||
}
|
||||
|
||||
private static TreeElement[] wrapDeclarations(List<JetDeclaration> declarations) {
|
||||
TreeElement[] result = new TreeElement[declarations.size()];
|
||||
for (int i = 0; i < declarations.size(); i++) {
|
||||
result[i] = new JetStructureViewElement(declarations.get(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package org.jetbrains.jet.plugin.structureView;
|
||||
|
||||
import com.intellij.ide.structureView.StructureViewModelBase;
|
||||
import com.intellij.ide.structureView.StructureViewTreeElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
@@ -11,5 +11,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class JetStructureViewModel extends StructureViewModelBase {
|
||||
public JetStructureViewModel(@NotNull PsiFile psiFile) {
|
||||
super(psiFile, new JetStructureViewElement(psiFile));
|
||||
withSuitableClasses(JetDeclaration.class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user