Jet class contributor. Contributes everything that can't be produced with Java.
This commit is contained in:
@@ -17,6 +17,8 @@
|
|||||||
package org.jetbrains.jet.lang.psi;
|
package org.jetbrains.jet.lang.psi;
|
||||||
|
|
||||||
import com.intellij.lang.ASTNode;
|
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.openapi.util.text.StringUtil;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
@@ -37,8 +39,7 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* @author max
|
* @author max
|
||||||
*/
|
*/
|
||||||
public class JetClass extends JetTypeParameterListOwnerStub<PsiJetClassStub>
|
public class JetClass extends JetTypeParameterListOwnerStub<PsiJetClassStub> implements JetClassOrObject {
|
||||||
implements JetClassOrObject, JetModifierListOwner {
|
|
||||||
|
|
||||||
public JetClass(@NotNull ASTNode node) {
|
public JetClass(@NotNull ASTNode node) {
|
||||||
super(node);
|
super(node);
|
||||||
@@ -48,6 +49,7 @@ public class JetClass extends JetTypeParameterListOwnerStub<PsiJetClassStub>
|
|||||||
super(stub, JetStubElementTypes.CLASS);
|
super(stub, JetStubElementTypes.CLASS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public List<JetDeclaration> getDeclarations() {
|
public List<JetDeclaration> getDeclarations() {
|
||||||
JetClassBody body = (JetClassBody) findChildByType(JetNodeTypes.CLASS_BODY);
|
JetClassBody body = (JetClassBody) findChildByType(JetNodeTypes.CLASS_BODY);
|
||||||
@@ -104,6 +106,7 @@ public class JetClass extends JetTypeParameterListOwnerStub<PsiJetClassStub>
|
|||||||
return (JetModifierList) findChildByType(JetNodeTypes.PRIMARY_CONSTRUCTOR_MODIFIER_LIST);
|
return (JetModifierList) findChildByType(JetNodeTypes.PRIMARY_CONSTRUCTOR_MODIFIER_LIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<JetClassInitializer> getAnonymousInitializers() {
|
public List<JetClassInitializer> getAnonymousInitializers() {
|
||||||
JetClassBody body = getBody();
|
JetClassBody body = getBody();
|
||||||
@@ -112,6 +115,7 @@ public class JetClass extends JetTypeParameterListOwnerStub<PsiJetClassStub>
|
|||||||
return body.getAnonymousInitializers();
|
return body.getAnonymousInitializers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPrimaryConstructor() {
|
public boolean hasPrimaryConstructor() {
|
||||||
return getPrimaryConstructorParameterList() != null;
|
return getPrimaryConstructorParameterList() != null;
|
||||||
}
|
}
|
||||||
@@ -249,8 +253,8 @@ public class JetClass extends JetTypeParameterListOwnerStub<PsiJetClassStub>
|
|||||||
return super.getName();
|
return super.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
//@Override
|
@Override
|
||||||
//public ItemPresentation getPresentation() {
|
public ItemPresentation getPresentation() {
|
||||||
// return ItemPresentationProviders.getItemPresentation(this);
|
return ItemPresentationProviders.getItemPresentation(this);
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,8 @@
|
|||||||
<internalFileTemplate name="Kotlin Enum"/>
|
<internalFileTemplate name="Kotlin Enum"/>
|
||||||
<internalFileTemplate name="Kotlin Trait"/>
|
<internalFileTemplate name="Kotlin Trait"/>
|
||||||
|
|
||||||
<gotoSymbolContributor implementation="org.jetbrains.jet.plugin.caches.GotoSymbolContributor"/>
|
<gotoSymbolContributor implementation="org.jetbrains.jet.plugin.caches.JetGotoSymbolContributor"/>
|
||||||
|
<gotoClassContributor implementation="org.jetbrains.jet.plugin.caches.JetGotoClassContributor"/>
|
||||||
<lang.importOptimizer language="jet" implementationClass="org.jetbrains.jet.plugin.editor.importOptimizer.JetImportOptimizer"/>
|
<lang.importOptimizer language="jet" implementationClass="org.jetbrains.jet.plugin.editor.importOptimizer.JetImportOptimizer"/>
|
||||||
|
|
||||||
<fileTypeFactory implementation="org.jetbrains.jet.plugin.JetFileFactory"/>
|
<fileTypeFactory implementation="org.jetbrains.jet.plugin.JetFileFactory"/>
|
||||||
@@ -166,6 +167,7 @@
|
|||||||
<codeInsight.lineMarkerProvider language="jet" implementationClass="org.jetbrains.jet.plugin.highlighter.JetLineMarkerProvider"/>
|
<codeInsight.lineMarkerProvider language="jet" implementationClass="org.jetbrains.jet.plugin.highlighter.JetLineMarkerProvider"/>
|
||||||
<iconProvider implementation="org.jetbrains.jet.plugin.JetIconProvider"/>
|
<iconProvider implementation="org.jetbrains.jet.plugin.JetIconProvider"/>
|
||||||
<itemPresentationProvider implementationClass="org.jetbrains.jet.plugin.presentation.JetFunctionPresenter" forClass="org.jetbrains.jet.lang.psi.JetNamedFunction"/>
|
<itemPresentationProvider implementationClass="org.jetbrains.jet.plugin.presentation.JetFunctionPresenter" forClass="org.jetbrains.jet.lang.psi.JetNamedFunction"/>
|
||||||
|
<itemPresentationProvider implementationClass="org.jetbrains.jet.plugin.presentation.JetClassPresenter" forClass="org.jetbrains.jet.lang.psi.JetClass"/>
|
||||||
<elementDescriptionProvider implementation="org.jetbrains.jet.plugin.findUsages.JetElementDescriptionProvider"/>
|
<elementDescriptionProvider implementation="org.jetbrains.jet.plugin.findUsages.JetElementDescriptionProvider"/>
|
||||||
<findUsagesHandlerFactory implementation="org.jetbrains.jet.plugin.findUsages.KotlinFindUsagesHandlerFactory"/>
|
<findUsagesHandlerFactory implementation="org.jetbrains.jet.plugin.findUsages.KotlinFindUsagesHandlerFactory"/>
|
||||||
<debugger.positionManagerFactory implementation="org.jetbrains.jet.plugin.debugger.JetPositionManagerFactory"/>
|
<debugger.positionManagerFactory implementation="org.jetbrains.jet.plugin.debugger.JetPositionManagerFactory"/>
|
||||||
|
|||||||
@@ -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<String> javaQualifiedNames = new HashSet<String>();
|
||||||
|
|
||||||
|
for (PsiClass aClass : classes) {
|
||||||
|
String qualifiedName = aClass.getQualifiedName();
|
||||||
|
if (qualifiedName != null) {
|
||||||
|
javaQualifiedNames.add(qualifiedName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<NavigationItem> items = new ArrayList<NavigationItem>();
|
||||||
|
Collection<JetClassOrObject> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -34,7 +34,7 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* @author Nikolay Krasko
|
* @author Nikolay Krasko
|
||||||
*/
|
*/
|
||||||
public class GotoSymbolContributor implements ChooseByNameContributor {
|
public class JetGotoSymbolContributor implements ChooseByNameContributor {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String[] getNames(Project project, boolean includeNonProjectItems) {
|
public String[] getNames(Project project, boolean includeNonProjectItems) {
|
||||||
@@ -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<JetClass> {
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user