mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
use java structure view for groovy
This commit is contained in:
+3
-3
@@ -19,15 +19,15 @@ import com.intellij.ide.structureView.StructureViewTreeElement;
|
||||
import com.intellij.ide.structureView.impl.common.PsiTreeElementBase;
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiJavaFile;
|
||||
import com.intellij.psi.PsiClassOwner;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class JavaFileTreeElement extends PsiTreeElementBase<PsiJavaFile> implements ItemPresentation {
|
||||
public JavaFileTreeElement(PsiJavaFile file) {
|
||||
public class JavaFileTreeElement extends PsiTreeElementBase<PsiClassOwner> implements ItemPresentation {
|
||||
public JavaFileTreeElement(PsiClassOwner file) {
|
||||
super(file);
|
||||
}
|
||||
|
||||
|
||||
+10
-12
@@ -33,10 +33,10 @@ import java.util.Collection;
|
||||
public class JavaFileTreeModel extends TextEditorBasedStructureViewModel implements StructureViewModel.ElementInfoProvider, PlaceHolder<String> {
|
||||
private static final Collection<NodeProvider> NODE_PROVIDERS = Arrays.<NodeProvider>asList(new JavaInheritedMembersNodeProvider(),
|
||||
new JavaAnonymousClassesNodeProvider());
|
||||
private final PsiJavaFile myFile;
|
||||
private final PsiClassOwner myFile;
|
||||
private String myPlace;
|
||||
|
||||
public JavaFileTreeModel(@NotNull PsiJavaFile file) {
|
||||
public JavaFileTreeModel(@NotNull PsiClassOwner file) {
|
||||
super(file);
|
||||
myFile = file;
|
||||
}
|
||||
@@ -94,19 +94,17 @@ public class JavaFileTreeModel extends TextEditorBasedStructureViewModel impleme
|
||||
if (super.isSuitable(element)) {
|
||||
if (element instanceof PsiMethod) {
|
||||
PsiMethod method = (PsiMethod)element;
|
||||
PsiElement parent = method.getParent();
|
||||
if (parent instanceof PsiClass) {
|
||||
return ((PsiClass)parent).getQualifiedName() != null;
|
||||
}
|
||||
PsiClass parent = method.getContainingClass();
|
||||
return parent != null && parent.getQualifiedName() != null;
|
||||
}
|
||||
else if (element instanceof PsiField) {
|
||||
|
||||
if (element instanceof PsiField) {
|
||||
PsiField field = (PsiField)element;
|
||||
PsiElement parent = field.getParent();
|
||||
if (parent instanceof PsiClass) {
|
||||
return ((PsiClass)parent).getQualifiedName() != null;
|
||||
}
|
||||
PsiClass parent = field.getContainingClass();
|
||||
return parent != null && parent.getQualifiedName() != null;
|
||||
}
|
||||
else if (element instanceof PsiClass) {
|
||||
|
||||
if (element instanceof PsiClass) {
|
||||
return ((PsiClass)element).getQualifiedName() != null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.structure;
|
||||
|
||||
import com.intellij.ide.structureView.impl.java.InheritedMembersFilter;
|
||||
import com.intellij.ide.util.treeView.smartTree.TreeElement;
|
||||
import org.jetbrains.plugins.groovy.structure.elements.GroovyStructureViewElement;
|
||||
|
||||
/**
|
||||
* @author Dmitry.Krasilschikov
|
||||
*/
|
||||
public class GroovyInheritFilter extends InheritedMembersFilter {
|
||||
@Override
|
||||
public boolean isVisible(TreeElement treeNode) {
|
||||
if (treeNode instanceof GroovyStructureViewElement){
|
||||
return !((GroovyStructureViewElement)treeNode).isInherited();
|
||||
}
|
||||
return super.isVisible(treeNode);
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.structure;
|
||||
|
||||
import com.intellij.ide.structureView.impl.java.PropertyGroup;
|
||||
import com.intellij.ide.structureView.impl.java.SuperTypeGroup;
|
||||
import com.intellij.ide.util.treeView.smartTree.ActionPresentation;
|
||||
import com.intellij.ide.util.treeView.smartTree.Sorter;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.structure.elements.impl.GroovyMethodStructureViewElement;
|
||||
import org.jetbrains.plugins.groovy.structure.elements.impl.GroovyTypeDefinitionStructureViewElement;
|
||||
import org.jetbrains.plugins.groovy.structure.elements.impl.GroovyVariableStructureViewElement;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class GroovyKindSorter implements Sorter {
|
||||
public static final Sorter INSTANCE = new GroovyKindSorter();
|
||||
|
||||
@NonNls public static final String ID = "KIND";
|
||||
private static final Comparator COMPARATOR = new Comparator() {
|
||||
public int compare(final Object o1, final Object o2) {
|
||||
return getWeight(o1) - getWeight(o2);
|
||||
}
|
||||
|
||||
private int getWeight(final Object value) {
|
||||
if (value instanceof GroovyTypeDefinitionStructureViewElement) {
|
||||
return 10;
|
||||
}
|
||||
if (value instanceof SuperTypeGroup) {
|
||||
return 20;
|
||||
}
|
||||
if (value instanceof GroovyMethodStructureViewElement) {
|
||||
final GroovyMethodStructureViewElement methodTreeElement = (GroovyMethodStructureViewElement)value;
|
||||
final PsiMethod method = (PsiMethod)methodTreeElement.getValue();
|
||||
return method != null && method.isConstructor() ? 30 : 35;
|
||||
}
|
||||
if (value instanceof PropertyGroup) {
|
||||
return 40;
|
||||
}
|
||||
if (value instanceof GroovyVariableStructureViewElement) {
|
||||
return 50;
|
||||
}
|
||||
return 60;
|
||||
}
|
||||
};
|
||||
|
||||
public Comparator getComparator() {
|
||||
return COMPARATOR;
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ActionPresentation getPresentation() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return ID;
|
||||
}
|
||||
}
|
||||
+13
-1
@@ -19,21 +19,33 @@ package org.jetbrains.plugins.groovy.structure;
|
||||
* User: Dmitry.Krasilschikov
|
||||
* Date: 19.06.2008
|
||||
*/
|
||||
|
||||
import com.intellij.ide.structureView.StructureViewBuilder;
|
||||
import com.intellij.ide.structureView.StructureViewModel;
|
||||
import com.intellij.ide.structureView.TreeBasedStructureViewBuilder;
|
||||
import com.intellij.ide.structureView.impl.java.JavaFileTreeModel;
|
||||
import com.intellij.ide.structureView.impl.java.JavaInheritedMembersNodeProvider;
|
||||
import com.intellij.ide.util.treeView.smartTree.NodeProvider;
|
||||
import com.intellij.lang.PsiStructureViewFactory;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
public class GroovyStructureViewFactory implements PsiStructureViewFactory {
|
||||
public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
|
||||
return new TreeBasedStructureViewBuilder() {
|
||||
|
||||
@NotNull
|
||||
public StructureViewModel createStructureViewModel() {
|
||||
return new GroovyStructureViewModel((GroovyFileBase) psiFile);
|
||||
return new JavaFileTreeModel((GroovyFileBase)psiFile) {
|
||||
@Override
|
||||
public Collection<NodeProvider> getNodeProviders() {
|
||||
return Arrays.<NodeProvider>asList(new JavaInheritedMembersNodeProvider());
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
-117
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.structure;
|
||||
|
||||
import com.intellij.ide.structureView.StructureViewTreeElement;
|
||||
import com.intellij.ide.structureView.TextEditorBasedStructureViewModel;
|
||||
import com.intellij.ide.util.treeView.smartTree.Filter;
|
||||
import com.intellij.ide.util.treeView.smartTree.Sorter;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
|
||||
import org.jetbrains.plugins.groovy.structure.elements.impl.GroovyFileStructureViewElement;
|
||||
|
||||
/**
|
||||
* User: Dmitry.Krasilschikov
|
||||
* Date: 21.05.2007
|
||||
*/
|
||||
|
||||
public class GroovyStructureViewModel extends TextEditorBasedStructureViewModel {
|
||||
private final GroovyFileBase myRootElement;
|
||||
|
||||
private static final Class[] SUITABLE_CLASSES =
|
||||
new Class[]{GroovyFileBase.class, GrTypeDefinition.class, GrMethod.class, GrVariable.class};
|
||||
|
||||
public GroovyStructureViewModel(GroovyFileBase rootElement) {
|
||||
super(rootElement);
|
||||
myRootElement = rootElement;
|
||||
}
|
||||
|
||||
protected PsiFile getPsiFile() {
|
||||
return myRootElement;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public StructureViewTreeElement getRoot() {
|
||||
return new GroovyFileStructureViewElement(myRootElement);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Sorter[] getSorters() {
|
||||
return new Sorter[]{GroovyKindSorter.INSTANCE, Sorter.ALPHA_SORTER};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Filter[] getFilters() {
|
||||
return new Filter[]{new GroovyInheritFilter()};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldEnterElement(Object element) {
|
||||
return element instanceof GrTypeDefinition;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Class[] getSuitableClasses() {
|
||||
return SUITABLE_CLASSES;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Object findAcceptableElement(PsiElement element) {
|
||||
while (element != null && !(element instanceof PsiDirectory)) {
|
||||
if (isSuitable(element)) {
|
||||
if (element instanceof GroovyFileBase && ((GroovyFileBase)element).getTypeDefinitions().length == 1) {
|
||||
return ((GroovyFileBase)element).getTypeDefinitions()[0];
|
||||
}
|
||||
return element;
|
||||
}
|
||||
element = element.getParent();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSuitable(final PsiElement element) {
|
||||
if (super.isSuitable(element)) {
|
||||
if (element instanceof GrMethod) {
|
||||
GrMethod method = (GrMethod)element;
|
||||
PsiElement parent = method.getParent().getParent();
|
||||
if (parent instanceof GrTypeDefinition) {
|
||||
return ((GrTypeDefinition)parent).getQualifiedName() != null;
|
||||
}
|
||||
}
|
||||
else if (element instanceof GrVariable) {
|
||||
GrVariable field = (GrVariable)element;
|
||||
PsiElement parent = field.getParent().getParent().getParent();
|
||||
if (parent instanceof GrTypeDefinition) {
|
||||
return ((GrTypeDefinition)parent).getQualifiedName() != null;
|
||||
}
|
||||
}
|
||||
else if (element instanceof GrTypeDefinition) {
|
||||
return ((GrTypeDefinition)element).getQualifiedName() != null;
|
||||
} else if (element instanceof GroovyFileBase) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
-78
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.structure.elements;
|
||||
|
||||
import com.intellij.ide.structureView.StructureViewTreeElement;
|
||||
import com.intellij.pom.Navigatable;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* User: Dmitry.Krasilschikov
|
||||
* Date: 21.05.2007
|
||||
*/
|
||||
|
||||
abstract public class GroovyStructureViewElement implements StructureViewTreeElement {
|
||||
final protected PsiElement myElement;
|
||||
final protected boolean myIsInherited;
|
||||
|
||||
public GroovyStructureViewElement(PsiElement element, boolean isInherited) {
|
||||
myElement = element;
|
||||
myIsInherited = isInherited;
|
||||
}
|
||||
|
||||
public GroovyStructureViewElement(PsiElement element) {
|
||||
this(element, false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Object getValue() {
|
||||
return myElement.isValid() ? myElement : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
GroovyStructureViewElement that = (GroovyStructureViewElement)o;
|
||||
|
||||
if (myElement != null ? !myElement.equals(that.myElement) : that.myElement != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return myElement != null ? myElement.hashCode() : 0;
|
||||
}
|
||||
|
||||
public void navigate(boolean b) {
|
||||
((Navigatable) myElement).navigate(b);
|
||||
}
|
||||
|
||||
public boolean canNavigate() {
|
||||
return ((Navigatable) myElement).canNavigate();
|
||||
}
|
||||
|
||||
public boolean canNavigateToSource() {
|
||||
return ((Navigatable) myElement).canNavigateToSource();
|
||||
}
|
||||
|
||||
public boolean isInherited() {
|
||||
return myIsInherited;
|
||||
}
|
||||
}
|
||||
-68
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.structure.elements.impl;
|
||||
|
||||
import com.intellij.ide.util.treeView.smartTree.TreeElement;
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.GrTopStatement;
|
||||
import org.jetbrains.plugins.groovy.structure.elements.GroovyStructureViewElement;
|
||||
import org.jetbrains.plugins.groovy.structure.itemsPresentations.GroovyItemPresentation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* User: Dmitry.Krasilschikov
|
||||
* Date: 30.10.2007
|
||||
*/
|
||||
public class GroovyFileStructureViewElement extends GroovyStructureViewElement {
|
||||
public GroovyFileStructureViewElement(GroovyFileBase groovyFileBase) {
|
||||
super(groovyFileBase);
|
||||
}
|
||||
|
||||
public ItemPresentation getPresentation() {
|
||||
return new GroovyItemPresentation(myElement) {
|
||||
public String getPresentableText() {
|
||||
return ((GroovyFileBase) myElement).getName();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public TreeElement[] getChildren() {
|
||||
List<GroovyStructureViewElement> children = new ArrayList<GroovyStructureViewElement>();
|
||||
|
||||
for (GrTopStatement topStatement : ((GroovyFileBase) myElement).getTopStatements()) {
|
||||
if (topStatement instanceof GrTypeDefinition) {
|
||||
children.add(new GroovyTypeDefinitionStructureViewElement(((GrTypeDefinition)topStatement)));
|
||||
} else if (topStatement instanceof GrMethod) {
|
||||
children.add(new GroovyMethodStructureViewElement(((GrMethod) topStatement), false));
|
||||
|
||||
} else if (topStatement instanceof GrVariableDeclaration) {
|
||||
for (final GrVariable variable : ((GrVariableDeclaration) topStatement).getVariables()) {
|
||||
children.add(new GroovyVariableStructureViewElement(variable, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return children.toArray(new GroovyStructureViewElement[children.size()]);
|
||||
}
|
||||
}
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.structure.elements.impl;
|
||||
|
||||
import com.intellij.ide.structureView.StructureViewTreeElement;
|
||||
import com.intellij.ide.util.treeView.smartTree.TreeElement;
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import org.jetbrains.plugins.groovy.structure.elements.GroovyStructureViewElement;
|
||||
import org.jetbrains.plugins.groovy.structure.itemsPresentations.impl.GroovyMethodItemPresentation;
|
||||
|
||||
/**
|
||||
* User: Dmitry.Krasilschikov
|
||||
* Date: 30.10.2007
|
||||
*/
|
||||
public class GroovyMethodStructureViewElement extends GroovyStructureViewElement {
|
||||
|
||||
public GroovyMethodStructureViewElement(PsiMethod element, boolean isInherit) {
|
||||
super(element, isInherit);
|
||||
}
|
||||
|
||||
public ItemPresentation getPresentation() {
|
||||
return new GroovyMethodItemPresentation(((PsiMethod) myElement), isInherited());
|
||||
}
|
||||
|
||||
public TreeElement[] getChildren() {
|
||||
return StructureViewTreeElement.EMPTY_ARRAY;
|
||||
}
|
||||
}
|
||||
-92
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.structure.elements.impl;
|
||||
|
||||
import com.intellij.ide.util.treeView.smartTree.TreeElement;
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrReflectedMethod;
|
||||
import org.jetbrains.plugins.groovy.structure.elements.GroovyStructureViewElement;
|
||||
import org.jetbrains.plugins.groovy.structure.itemsPresentations.GroovyItemPresentation;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class GroovyTypeDefinitionStructureViewElement extends GroovyStructureViewElement {
|
||||
public GroovyTypeDefinitionStructureViewElement(GrTypeDefinition typeDefinition) {
|
||||
super(typeDefinition);
|
||||
}
|
||||
|
||||
public ItemPresentation getPresentation() {
|
||||
return new GroovyItemPresentation(myElement) {
|
||||
public String getPresentableText() {
|
||||
return ((GrTypeDefinition) myElement).getNameIdentifierGroovy().getText();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public TreeElement[] getChildren() {
|
||||
if (!myElement.isValid()) {
|
||||
return EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
Set<GroovyStructureViewElement> children = new LinkedHashSet<GroovyStructureViewElement>();
|
||||
|
||||
//adding statements for type definition
|
||||
final GrTypeDefinition typeDefinition = (GrTypeDefinition)myElement;
|
||||
for (PsiClass innerClass : typeDefinition.getInnerClasses()) {
|
||||
if (innerClass instanceof GrTypeDefinition) {
|
||||
children.add(new GroovyTypeDefinitionStructureViewElement((GrTypeDefinition)innerClass));
|
||||
}
|
||||
}
|
||||
|
||||
Set<PsiField> fields = new HashSet<PsiField>();
|
||||
ContainerUtil.addAll(fields, typeDefinition.getFields());
|
||||
|
||||
for (PsiField field : typeDefinition.getAllFields()) {
|
||||
final boolean contains = fields.contains(field);
|
||||
if (contains || !field.hasModifierProperty(PsiModifier.PRIVATE)) {
|
||||
children.add(new GroovyVariableStructureViewElement(field, !contains));
|
||||
}
|
||||
}
|
||||
|
||||
Set<PsiMethod> methods = new HashSet<PsiMethod>();
|
||||
ContainerUtil.addAll(methods, typeDefinition.getGroovyMethods());
|
||||
|
||||
for (PsiMethod method : typeDefinition.getAllMethods()) {
|
||||
if (!method.isPhysical()) continue;
|
||||
|
||||
if (method instanceof GrReflectedMethod) {
|
||||
method = ((GrReflectedMethod)method).getBaseMethod();
|
||||
}
|
||||
if (methods.contains(method)) {
|
||||
children.add(new GroovyMethodStructureViewElement(method, false));
|
||||
}
|
||||
else {
|
||||
children.add(new GroovyMethodStructureViewElement(method, true));
|
||||
}
|
||||
}
|
||||
|
||||
return children.toArray(new GroovyStructureViewElement[children.size()]);
|
||||
}
|
||||
}
|
||||
|
||||
-49
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.structure.elements.impl;
|
||||
|
||||
import com.intellij.ide.util.treeView.smartTree.TreeElement;
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.openapi.util.Iconable;
|
||||
import com.intellij.psi.PsiVariable;
|
||||
import org.jetbrains.plugins.groovy.structure.elements.GroovyStructureViewElement;
|
||||
import org.jetbrains.plugins.groovy.structure.itemsPresentations.impl.GroovyVariableItemPresentation;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* User: Dmitry.Krasilschikov
|
||||
* Date: 30.10.2007
|
||||
*/
|
||||
public class GroovyVariableStructureViewElement extends GroovyStructureViewElement {
|
||||
final Icon icon;
|
||||
private final PsiVariable myVariable;
|
||||
|
||||
public GroovyVariableStructureViewElement(PsiVariable variable, boolean isInherited) {
|
||||
super(variable, isInherited);
|
||||
myVariable = variable;
|
||||
icon = myVariable.getIcon(Iconable.ICON_FLAG_OPEN);
|
||||
}
|
||||
|
||||
public ItemPresentation getPresentation() {
|
||||
return new GroovyVariableItemPresentation(myVariable);
|
||||
}
|
||||
|
||||
public TreeElement[] getChildren() {
|
||||
return GroovyStructureViewElement.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
}
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.structure.itemsPresentations;
|
||||
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.openapi.util.Iconable;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* User: Dmitry.Krasilschikov
|
||||
* Date: 30.10.2007
|
||||
*/
|
||||
public abstract class GroovyItemPresentation implements ItemPresentation {
|
||||
protected final PsiElement myElement;
|
||||
|
||||
protected GroovyItemPresentation(PsiElement myElement) {
|
||||
this.myElement = myElement;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getLocationString() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Icon getIcon(boolean open) {
|
||||
return myElement.getIcon(Iconable.ICON_FLAG_OPEN);
|
||||
}
|
||||
}
|
||||
-86
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.structure.itemsPresentations.impl;
|
||||
|
||||
import com.intellij.navigation.ColoredItemPresentation;
|
||||
import com.intellij.openapi.editor.colors.CodeInsightColors;
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import com.intellij.openapi.util.NotNullLazyValue;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiParameter;
|
||||
import com.intellij.psi.PsiParameterList;
|
||||
import com.intellij.psi.PsiType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter;
|
||||
import org.jetbrains.plugins.groovy.structure.itemsPresentations.GroovyItemPresentation;
|
||||
|
||||
/**
|
||||
* User: Dmitry.Krasilschikov
|
||||
* Date: 31.10.2007
|
||||
*/
|
||||
public class GroovyMethodItemPresentation extends GroovyItemPresentation implements ColoredItemPresentation {
|
||||
private final boolean isInherit;
|
||||
private final NotNullLazyValue<String> myPresentableText = new NotNullLazyValue<String>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected String compute() {
|
||||
final PsiMethod method = (PsiMethod)myElement;
|
||||
StringBuilder presentableText = new StringBuilder();
|
||||
presentableText.append(method.getName());
|
||||
presentableText.append(' ');
|
||||
|
||||
PsiParameterList paramList = method.getParameterList();
|
||||
PsiParameter[] parameters = paramList.getParameters();
|
||||
|
||||
presentableText.append('(');
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
if (i > 0) presentableText.append(", ");
|
||||
|
||||
PsiParameter p = parameters[i];
|
||||
boolean isOptional = p instanceof GrParameter && ((GrParameter)p).isOptional();
|
||||
if (isOptional) presentableText.append('[');
|
||||
presentableText.append(p.getType().getPresentableText());
|
||||
if (isOptional) presentableText.append(']');
|
||||
}
|
||||
presentableText.append(')');
|
||||
|
||||
PsiType returnType = method.getReturnType();
|
||||
|
||||
if (returnType != null) {
|
||||
presentableText.append(':');
|
||||
presentableText.append(returnType.getPresentableText());
|
||||
}
|
||||
|
||||
return presentableText.toString();
|
||||
}
|
||||
};
|
||||
|
||||
public GroovyMethodItemPresentation(PsiMethod myElement, boolean isInherit) {
|
||||
super(myElement);
|
||||
this.isInherit = isInherit;
|
||||
}
|
||||
|
||||
public String getPresentableText() {
|
||||
return myPresentableText.getValue();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public TextAttributesKey getTextAttributesKey() {
|
||||
return isInherit ? CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES : null;
|
||||
}
|
||||
}
|
||||
-47
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.structure.itemsPresentations.impl;
|
||||
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.PsiVariable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
|
||||
import org.jetbrains.plugins.groovy.structure.itemsPresentations.GroovyItemPresentation;
|
||||
|
||||
/**
|
||||
* User: Dmitry.Krasilschikov
|
||||
* Date: 31.10.2007
|
||||
*/
|
||||
public class GroovyVariableItemPresentation extends GroovyItemPresentation {
|
||||
private final PsiVariable myVariable;
|
||||
|
||||
public GroovyVariableItemPresentation(PsiVariable variable) {
|
||||
super(variable);
|
||||
|
||||
myVariable = variable;
|
||||
}
|
||||
|
||||
public String getPresentableText() {
|
||||
StringBuilder presentableText = new StringBuilder();
|
||||
|
||||
presentableText.append(myVariable.getName());
|
||||
if (!(myVariable instanceof GrVariable) || ((GrVariable)myVariable).getTypeElementGroovy() != null) {
|
||||
PsiType varType = myVariable.getType();
|
||||
presentableText.append(":");
|
||||
presentableText.append(varType.getPresentableText());
|
||||
}
|
||||
return presentableText.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user