From 508759ca8b72bb4384016cca63d9b3e52d4dd0fd Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Fri, 15 Jun 2012 21:31:21 +0400 Subject: [PATCH] Jet class contributor. Contributes everything that can't be produced with Java. --- .../org/jetbrains/jet/lang/psi/JetClass.java | 16 ++-- idea/src/META-INF/plugin.xml | 4 +- .../caches/JetGotoClassContributor.java | 93 +++++++++++++++++++ ...tor.java => JetGotoSymbolContributor.java} | 2 +- .../presentation/JetClassPresenter.java | 64 +++++++++++++ 5 files changed, 171 insertions(+), 8 deletions(-) create mode 100644 idea/src/org/jetbrains/jet/plugin/caches/JetGotoClassContributor.java rename idea/src/org/jetbrains/jet/plugin/caches/{GotoSymbolContributor.java => JetGotoSymbolContributor.java} (96%) create mode 100644 idea/src/org/jetbrains/jet/plugin/presentation/JetClassPresenter.java diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClass.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClass.java index 7e9bf8f4e20..673a97744d2 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClass.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClass.java @@ -17,6 +17,8 @@ package org.jetbrains.jet.lang.psi; import com.intellij.lang.ASTNode; +import com.intellij.navigation.ItemPresentation; +import com.intellij.navigation.ItemPresentationProviders; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; @@ -37,8 +39,7 @@ import java.util.List; /** * @author max */ -public class JetClass extends JetTypeParameterListOwnerStub - implements JetClassOrObject, JetModifierListOwner { +public class JetClass extends JetTypeParameterListOwnerStub implements JetClassOrObject { public JetClass(@NotNull ASTNode node) { super(node); @@ -48,6 +49,7 @@ public class JetClass extends JetTypeParameterListOwnerStub super(stub, JetStubElementTypes.CLASS); } + @NotNull @Override public List getDeclarations() { JetClassBody body = (JetClassBody) findChildByType(JetNodeTypes.CLASS_BODY); @@ -104,6 +106,7 @@ public class JetClass extends JetTypeParameterListOwnerStub return (JetModifierList) findChildByType(JetNodeTypes.PRIMARY_CONSTRUCTOR_MODIFIER_LIST); } + @Override @NotNull public List getAnonymousInitializers() { JetClassBody body = getBody(); @@ -112,6 +115,7 @@ public class JetClass extends JetTypeParameterListOwnerStub return body.getAnonymousInitializers(); } + @Override public boolean hasPrimaryConstructor() { return getPrimaryConstructorParameterList() != null; } @@ -249,8 +253,8 @@ public class JetClass extends JetTypeParameterListOwnerStub return super.getName(); } - //@Override - //public ItemPresentation getPresentation() { - // return ItemPresentationProviders.getItemPresentation(this); - //} + @Override + public ItemPresentation getPresentation() { + return ItemPresentationProviders.getItemPresentation(this); + } } diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index a7049fcc191..7dc4135941d 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -78,7 +78,8 @@ - + + @@ -166,6 +167,7 @@ + diff --git a/idea/src/org/jetbrains/jet/plugin/caches/JetGotoClassContributor.java b/idea/src/org/jetbrains/jet/plugin/caches/JetGotoClassContributor.java new file mode 100644 index 00000000000..f1e3489b772 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/caches/JetGotoClassContributor.java @@ -0,0 +1,93 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.caches; + +import com.intellij.navigation.GotoClassContributor; +import com.intellij.navigation.NavigationItem; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiClass; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.util.ArrayUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.psi.*; +import org.jetbrains.jet.lang.resolve.name.FqName; +import org.jetbrains.jet.plugin.stubindex.JetShortClassNameIndex; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; + +/** + * @author Nikolay Krasko + */ +public class JetGotoClassContributor implements GotoClassContributor { + @Override + public String getQualifiedName(NavigationItem item) { + return "Hello"; + } + + @Override + public String getQualifiedNameSeparator() { + return "."; + } + + @NotNull + @Override + public String[] getNames(Project project, boolean includeNonProjectItems) { + return JetCacheManager.getInstance(project).getNamesCache().getAllClassNames(); + } + + @NotNull + @Override + public NavigationItem[] getItemsByName(String name, String pattern, Project project, boolean includeNonProjectItems) { + final GlobalSearchScope scope = GlobalSearchScope.allScope(project); + PsiClass[] classes = JetCacheManager.getInstance(project).getNamesCache().getClassesByName(name, scope); + + HashSet javaQualifiedNames = new HashSet(); + + for (PsiClass aClass : classes) { + String qualifiedName = aClass.getQualifiedName(); + if (qualifiedName != null) { + javaQualifiedNames.add(qualifiedName); + } + } + + ArrayList items = new ArrayList(); + Collection classesOrObjects = JetShortClassNameIndex.getInstance().get(name, project, scope); + + for (JetClassOrObject classOrObject : classesOrObjects) { + if (classOrObject instanceof JetNamedDeclaration) { + FqName fqName = JetPsiUtil.getFQName((JetNamedDeclaration) classOrObject); + if (fqName == null || javaQualifiedNames.contains(fqName.toString())) { + continue; + } + + if (classOrObject instanceof JetObjectDeclaration) { + // items.add((JetObjectDeclaration) classOrObject); + } + else if (classOrObject instanceof JetClass) { + items.add((JetClass) classOrObject); + } + else { + assert false; + } + } + } + + return ArrayUtil.toObjectArray(items, NavigationItem.class); + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/caches/GotoSymbolContributor.java b/idea/src/org/jetbrains/jet/plugin/caches/JetGotoSymbolContributor.java similarity index 96% rename from idea/src/org/jetbrains/jet/plugin/caches/GotoSymbolContributor.java rename to idea/src/org/jetbrains/jet/plugin/caches/JetGotoSymbolContributor.java index 74f6b480202..402e6c2e13d 100644 --- a/idea/src/org/jetbrains/jet/plugin/caches/GotoSymbolContributor.java +++ b/idea/src/org/jetbrains/jet/plugin/caches/JetGotoSymbolContributor.java @@ -34,7 +34,7 @@ import java.util.List; /** * @author Nikolay Krasko */ -public class GotoSymbolContributor implements ChooseByNameContributor { +public class JetGotoSymbolContributor implements ChooseByNameContributor { @NotNull @Override public String[] getNames(Project project, boolean includeNonProjectItems) { diff --git a/idea/src/org/jetbrains/jet/plugin/presentation/JetClassPresenter.java b/idea/src/org/jetbrains/jet/plugin/presentation/JetClassPresenter.java new file mode 100644 index 00000000000..37108920992 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/presentation/JetClassPresenter.java @@ -0,0 +1,64 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.presentation; + +import com.intellij.navigation.ColoredItemPresentation; +import com.intellij.navigation.ItemPresentation; +import com.intellij.navigation.ItemPresentationProvider; +import com.intellij.openapi.editor.colors.TextAttributesKey; +import org.jetbrains.jet.lang.psi.JetClass; +import org.jetbrains.jet.lang.psi.JetPsiUtil; +import org.jetbrains.jet.lang.resolve.name.FqName; +import org.jetbrains.jet.plugin.JetIconProvider; + +import javax.swing.*; + +/** + * @author Nikolay Krasko + */ +public class JetClassPresenter implements ItemPresentationProvider { + + @Override + public ItemPresentation getPresentation(final JetClass item) { + return new ColoredItemPresentation() { + @Override + public TextAttributesKey getTextAttributesKey() { + return null; + } + + @Override + public String getPresentableText() { + return item.getName(); + } + + @Override + public String getLocationString() { + FqName name = JetPsiUtil.getFQName(item); + if (name != null) { + return name.toString(); + } + + return ""; + } + + @Override + public Icon getIcon(boolean open) { + return JetIconProvider.INSTANCE.getIcon(item, 0); + } + }; + } +}