don't show synthetic methods in groovy structure view

This commit is contained in:
peter
2012-01-05 20:38:46 +01:00
parent 6d51f2738f
commit d3329c8512
8 changed files with 135 additions and 23 deletions
@@ -16,6 +16,7 @@
package com.intellij.ide.structureView.impl;
import com.intellij.psi.*;
import com.intellij.psi.impl.PsiImplUtil;
import com.intellij.psi.scope.BaseScopeProcessor;
import com.intellij.psi.util.MethodSignature;
import com.intellij.psi.util.PsiUtil;
@@ -55,11 +56,11 @@ public class AddAllMembersProcessor extends BaseScopeProcessor {
PsiMethod psiMethod = (PsiMethod)member;
if (shouldAdd(psiMethod)) {
mapMethodBySignature(psiMethod);
myAllMembers.add(psiMethod);
myAllMembers.add(PsiImplUtil.handleMirror(psiMethod));
}
}
else {
myAllMembers.add(member);
myAllMembers.add(PsiImplUtil.handleMirror(member));
}
}
return true;
@@ -17,7 +17,7 @@ package com.intellij.ide.structureView.impl.java;
import com.intellij.ide.structureView.StructureViewTreeElement;
import com.intellij.psi.*;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.psi.impl.PsiImplUtil;
import org.jetbrains.annotations.NotNull;
import java.util.*;
@@ -43,11 +43,7 @@ public class JavaClassTreeElement extends JavaClassTreeElementBase<PsiClass> {
final PsiClass aClass = getElement();
if (aClass == null) return Collections.emptyList();
Collection<PsiElement> members = new ArrayList<PsiElement>();
ContainerUtil.addAll(members, aClass.getFields());
ContainerUtil.addAll(members, aClass.getMethods());
ContainerUtil.addAll(members, aClass.getInnerClasses());
ContainerUtil.addAll(members, aClass.getInitializers());
LinkedHashSet<PsiElement> members = getOwnChildren(aClass);
List<StructureViewTreeElement> children = new ArrayList<StructureViewTreeElement>(members.size());
//aClass.processDeclarations(new AddAllMembersProcessor(inherited, aClass), ResolveState.initial(), null, aClass);
@@ -70,6 +66,21 @@ public class JavaClassTreeElement extends JavaClassTreeElementBase<PsiClass> {
return children;
}
static LinkedHashSet<PsiElement> getOwnChildren(PsiClass aClass) {
LinkedHashSet<PsiElement> members = new LinkedHashSet<PsiElement>();
addPhysicalElements(aClass.getFields(), members);
addPhysicalElements(aClass.getMethods(), members);
addPhysicalElements(aClass.getInnerClasses(), members);
addPhysicalElements(aClass.getInitializers(), members);
return members;
}
private static void addPhysicalElements(PsiElement[] elements, LinkedHashSet<PsiElement> to) {
for (PsiElement element : elements) {
to.add(PsiImplUtil.handleMirror(element));
}
}
public Set<PsiClass> getParents() {
return myParents;
}
@@ -26,7 +26,6 @@ import com.intellij.openapi.keymap.KeymapManager;
import com.intellij.openapi.util.IconLoader;
import com.intellij.psi.*;
import com.intellij.util.containers.ContainerUtil;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -51,11 +50,7 @@ public class JavaInheritedMembersNodeProvider implements FileStructureNodeProvid
if (node instanceof JavaClassTreeElement) {
final PsiClass aClass = ((JavaClassTreeElement)node).getValue();
Collection<PsiElement> inherited = new LinkedHashSet<PsiElement>();
Collection<PsiElement> ownChildren = new THashSet<PsiElement>();
ContainerUtil.addAll(ownChildren, aClass.getFields());
ContainerUtil.addAll(ownChildren, aClass.getMethods());
ContainerUtil.addAll(ownChildren, aClass.getInnerClasses());
ContainerUtil.addAll(ownChildren, aClass.getInitializers());
Collection<PsiElement> ownChildren = JavaClassTreeElement.getOwnChildren(aClass);
aClass.processDeclarations(new AddAllMembersProcessor(inherited, aClass), ResolveState.initial(), null, aClass);
inherited.removeAll(ownChildren);
+1
View File
@@ -12,6 +12,7 @@
<orderEntry type="module" module-name="resources-en" />
<orderEntry type="library" name="Guava" level="project" />
<orderEntry type="library" name="asm" level="project" />
<orderEntry type="module" module-name="lang-api" />
</component>
</module>
@@ -530,4 +530,8 @@ public class PsiImplUtil {
PsiParameter[] parameters = method.getParameterList().getParameters();
return parameters.length > 0 && parameters[parameters.length - 1].isVarArgs();
}
public static PsiElement handleMirror(PsiElement element) {
return element instanceof PsiMirrorElement ? ((PsiMirrorElement)element).getPrototype() : element;
}
}
@@ -30,6 +30,7 @@ import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.util.Pair;
import com.intellij.psi.*;
import com.intellij.psi.impl.PsiImplUtil;
import com.intellij.psi.search.searches.AllOverridingMethodsSearch;
import com.intellij.psi.search.searches.SuperMethodsSearch;
import com.intellij.psi.util.MethodSignatureBackedByPsiMethod;
@@ -205,7 +206,7 @@ public class GroovyLineMarkerProvider extends JavaLineMarkerProvider {
if (superMethod instanceof PsiMirrorElement) {
}
overridden.add(superMethod instanceof PsiMirrorElement ? ((PsiMirrorElement)superMethod).getPrototype() : superMethod);
overridden.add(PsiImplUtil.handleMirror(superMethod));
}
}
return !methods.isEmpty();
@@ -219,9 +220,9 @@ public class GroovyLineMarkerProvider extends JavaLineMarkerProvider {
for (PsiElement element : overridden) {
final Icon icon = OVERRIDEN_METHOD_MARKER_RENDERER;
PsiElement range;
if (element instanceof PsiMirrorElement) element = ((PsiMirrorElement)element).getPrototype();
element = PsiImplUtil.handleMirror(element);
if (element instanceof GrNamedElement) {
range = ((GrNamedElement)element).getNameIdentifierGroovy();
}
@@ -340,12 +340,7 @@ public class GroovyMarkerTypes {
new CommonProcessors.CollectProcessor<PsiMethod>() {
@Override
public boolean process(PsiMethod psiMethod) {
if (psiMethod instanceof PsiMirrorElement) {
updateComponent(((PsiMirrorElement)psiMethod).getPrototype(), myRenderer.getComparator());
}
else {
updateComponent(psiMethod, myRenderer.getComparator());
}
updateComponent(com.intellij.psi.impl.PsiImplUtil.handleMirror(psiMethod), myRenderer.getComparator());
return true;
}
});
@@ -0,0 +1,104 @@
/*
* Copyright 2000-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.plugins.groovy.lang
import com.intellij.ide.structureView.newStructureView.StructureViewComponent
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import com.intellij.util.Consumer
import static com.intellij.testFramework.PlatformTestUtil.assertTreeEqual
import com.intellij.ide.structureView.impl.java.JavaInheritedMembersNodeProvider
/**
* @author peter
*/
class GroovyStructureViewTest extends LightCodeInsightFixtureTestCase {
public void testSyntheticMethods() {
myFixture.configureByText 'a.groovy', '''
class Foo {
int prop
def Foo(int a, int b = 2) {}
def foo(int a, int b = 2) {}
}
'''
myFixture.testStructureView(new Consumer<StructureViewComponent>() {
@Override
public void consume(StructureViewComponent component) {
assertTreeEqual(component.getTree(), """-a.groovy
-Foo
Foo(int, int)
foo(int, int):Object
prop:int
""");
}
});
}
public void testInheritedSynthetic() {
myFixture.configureByText 'a.groovy', '''
class Foo {
int prop
def Foo(int a, int b = 2) {}
def foo(int a, int b = 2) {}
}
class Bar extends Foo {
def bar(int x = 239) {}
}
'''
myFixture.testStructureView(new Consumer<StructureViewComponent>() {
@Override
public void consume(StructureViewComponent component) {
component.setActionActive(JavaInheritedMembersNodeProvider.ID, true);
assertTreeEqual(component.getTree(), """-a.groovy
-Foo
Foo(int, int)
foo(int, int):Object
getClass():Class<? extends Object>
clone():Object
equals(Object):boolean
hashCode():int
wait(long):void
wait(long, int):void
wait():void
notify():void
finalize():void
toString():String
notifyAll():void
prop:int
-Bar
bar(int):Object
getClass():Class<? extends Object>
clone():Object
equals(Object):boolean
hashCode():int
foo(int, int):Object
wait(long):void
wait(long, int):void
wait():void
notify():void
finalize():void
toString():String
notifyAll():void
prop:int
""");
}
});
}
}