提交 c9d9001a 编写于 作者: D Dmitry Jemerov

structure view is in general working

上级 f16a4bb7
...@@ -22,11 +22,13 @@ ...@@ -22,11 +22,13 @@
<lang.braceMatcher language="jet" implementationClass="org.jetbrains.jet.lang.JetPairMatcher"/> <lang.braceMatcher language="jet" implementationClass="org.jetbrains.jet.lang.JetPairMatcher"/>
<lang.parserDefinition language="jet" implementationClass="org.jetbrains.jet.lang.parsing.JetParserDefinition"/> <lang.parserDefinition language="jet" implementationClass="org.jetbrains.jet.lang.parsing.JetParserDefinition"/>
<lang.commenter language="jet" implementationClass="org.jetbrains.jet.plugin.JetCommenter"/> <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.SoftKeywordsAnnotator"/>
<annotator language="jet" implementationClass="org.jetbrains.jet.lang.annotations.LabelsAnnotator"/> <annotator language="jet" implementationClass="org.jetbrains.jet.lang.annotations.LabelsAnnotator"/>
<annotator language="jet" implementationClass="org.jetbrains.jet.lang.annotations.JetPsiChecker"/> <annotator language="jet" implementationClass="org.jetbrains.jet.lang.annotations.JetPsiChecker"/>
<documentationProvider implementation="org.jetbrains.jet.plugin.JetQuickDocumentationProvider"/> <documentationProvider implementation="org.jetbrains.jet.plugin.JetQuickDocumentationProvider"/>
<configurationType implementation="org.jetbrains.jet.run.JetRunConfigurationType"/> <configurationType implementation="org.jetbrains.jet.run.JetRunConfigurationType"/>
<codeInsight.lineMarkerProvider language="jet" implementationClass="org.jetbrains.jet.lang.annotations.JetLineMarkerProvider"/> <codeInsight.lineMarkerProvider language="jet" implementationClass="org.jetbrains.jet.lang.annotations.JetLineMarkerProvider"/>
<iconProvider implementation="org.jetbrains.jet.plugin.JetIconProvider"/>
</extensions> </extensions>
</idea-plugin> </idea-plugin>
...@@ -11,19 +11,20 @@ import com.intellij.ide.util.DefaultPsiElementCellRenderer; ...@@ -11,19 +11,20 @@ import com.intellij.ide.util.DefaultPsiElementCellRenderer;
import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.Iconable;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtilBase; import com.intellij.psi.util.PsiUtilBase;
import com.intellij.ui.awt.RelativePoint; import com.intellij.ui.awt.RelativePoint;
import com.intellij.util.Function; import com.intellij.util.Function;
import com.intellij.util.Icons; import com.intellij.util.Icons;
import com.intellij.util.PsiIconUtil;
import com.intellij.util.PsiNavigateUtil; import com.intellij.util.PsiNavigateUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.AnalyzingUtils; import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.resolve.DescriptorRenderer; import org.jetbrains.jet.resolve.DescriptorRenderer;
import javax.swing.*; import javax.swing.*;
...@@ -38,7 +39,6 @@ import java.util.Set; ...@@ -38,7 +39,6 @@ import java.util.Set;
public class JetLineMarkerProvider implements LineMarkerProvider { public class JetLineMarkerProvider implements LineMarkerProvider {
public static final Icon OVERRIDING_FUNCTION = IconLoader.getIcon("/general/overridingMethod.png"); public static final Icon OVERRIDING_FUNCTION = IconLoader.getIcon("/general/overridingMethod.png");
public static final Icon ICON_FOR_OBJECT = Icons.ANONYMOUS_CLASS_ICON;
@Override @Override
public LineMarkerInfo getLineMarkerInfo(PsiElement element) { public LineMarkerInfo getLineMarkerInfo(PsiElement element) {
...@@ -49,47 +49,16 @@ public class JetLineMarkerProvider implements LineMarkerProvider { ...@@ -49,47 +49,16 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
if (element instanceof JetClass) { if (element instanceof JetClass) {
JetClass jetClass = (JetClass) element; JetClass jetClass = (JetClass) element;
Icon icon = jetClass.hasModifier(JetTokens.ENUM_KEYWORD) ? Icons.ENUM_ICON : Icons.CLASS_ICON; ClassDescriptor classDescriptor = bindingContext.getClassDescriptor(jetClass);
if (jetClass instanceof JetEnumEntry) { String text = classDescriptor == null ? "<i>Unresolved</i>" : DescriptorRenderer.HTML.render(classDescriptor);
JetEnumEntry enumEntry = (JetEnumEntry) jetClass; return createLineMarkerInfo(jetClass, text);
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) {
}
});
} }
if (element instanceof JetProperty) { if (element instanceof JetProperty) {
JetProperty jetProperty = (JetProperty) element; JetProperty jetProperty = (JetProperty) element;
final VariableDescriptor variableDescriptor = bindingContext.getVariableDescriptor(jetProperty); final VariableDescriptor variableDescriptor = bindingContext.getVariableDescriptor(jetProperty);
if (variableDescriptor instanceof PropertyDescriptor) { if (variableDescriptor instanceof PropertyDescriptor) {
return new LineMarkerInfo<JetProperty>(jetProperty, jetProperty.getTextOffset(), Icons.PROPERTY_ICON, Pass.UPDATE_ALL, return createLineMarkerInfo(element, DescriptorRenderer.HTML.render(variableDescriptor));
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) {
}
});
} }
} }
...@@ -164,22 +133,8 @@ public class JetLineMarkerProvider implements LineMarkerProvider { ...@@ -164,22 +133,8 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
} }
if (element instanceof JetNamespace) { if (element instanceof JetNamespace) {
JetNamespace jetNamespace = (JetNamespace) element; return createLineMarkerInfo((JetNamespace) element,
return new LineMarkerInfo<JetNamespace>( DescriptorRenderer.HTML.render(bindingContext.getNamespaceDescriptor((JetNamespace) element)));
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) {
}
}
);
} }
if (element instanceof JetObjectDeclaration && !(element.getParent() instanceof JetExpression)) { if (element instanceof JetObjectDeclaration && !(element.getParent() instanceof JetExpression)) {
...@@ -208,6 +163,23 @@ public class JetLineMarkerProvider implements LineMarkerProvider { ...@@ -208,6 +163,23 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
return null; 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) { private boolean isMember(@NotNull FunctionDescriptor functionDescriptor) {
return functionDescriptor.getContainingDeclaration().getOriginal() instanceof ClassifierDescriptor; return functionDescriptor.getContainingDeclaration().getOriginal() instanceof ClassifierDescriptor;
} }
......
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; ...@@ -5,9 +5,14 @@ import com.intellij.ide.util.treeView.smartTree.TreeElement;
import com.intellij.navigation.ItemPresentation; import com.intellij.navigation.ItemPresentation;
import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.util.Iconable; import com.intellij.openapi.util.Iconable;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.NavigatablePsiElement; import com.intellij.psi.NavigatablePsiElement;
import com.intellij.util.PsiIconUtil;
import org.jetbrains.jet.lang.psi.*;
import javax.swing.*; import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
/** /**
* @author yole * @author yole
...@@ -44,7 +49,13 @@ public class JetStructureViewElement implements StructureViewTreeElement { ...@@ -44,7 +49,13 @@ public class JetStructureViewElement implements StructureViewTreeElement {
return new ItemPresentation() { return new ItemPresentation() {
@Override @Override
public String getPresentableText() { public String getPresentableText() {
return ""; String name = myElement.getName();
if (StringUtil.isEmpty(name)) {
if (myElement instanceof JetClassInitializer) {
return "<class initializer>";
}
}
return name;
} }
@Override @Override
...@@ -54,7 +65,7 @@ public class JetStructureViewElement implements StructureViewTreeElement { ...@@ -54,7 +65,7 @@ public class JetStructureViewElement implements StructureViewTreeElement {
@Override @Override
public Icon getIcon(boolean open) { 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 @Override
...@@ -66,6 +77,36 @@ public class JetStructureViewElement implements StructureViewTreeElement { ...@@ -66,6 +77,36 @@ public class JetStructureViewElement implements StructureViewTreeElement {
@Override @Override
public TreeElement[] getChildren() { 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;
} }
} }
package org.jetbrains.jet.plugin.structureView; package org.jetbrains.jet.plugin.structureView;
import com.intellij.ide.structureView.StructureViewModelBase; import com.intellij.ide.structureView.StructureViewModelBase;
import com.intellij.ide.structureView.StructureViewTreeElement;
import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetDeclaration;
/** /**
* @author yole * @author yole
...@@ -11,5 +11,6 @@ import org.jetbrains.annotations.NotNull; ...@@ -11,5 +11,6 @@ import org.jetbrains.annotations.NotNull;
public class JetStructureViewModel extends StructureViewModelBase { public class JetStructureViewModel extends StructureViewModelBase {
public JetStructureViewModel(@NotNull PsiFile psiFile) { public JetStructureViewModel(@NotNull PsiFile psiFile) {
super(psiFile, new JetStructureViewElement(psiFile)); super(psiFile, new JetStructureViewElement(psiFile));
withSuitableClasses(JetDeclaration.class);
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册