Skip to content

Commit 555fefb

Browse files
committed
extract project view api
1 parent 42bcb8b commit 555fefb

8 files changed

Lines changed: 156 additions & 103 deletions

File tree

csharp-impl/src/main/java/consulo/csharp/impl/ide/projectView/CSharpProjectViewProvider.java

Lines changed: 44 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import consulo.application.Application;
2222
import consulo.application.dumb.DumbAware;
2323
import consulo.application.progress.ProgressManager;
24+
import consulo.csharp.projectView.CSharpProjectTreeNodeExpander;
2425
import consulo.dotnet.psi.DotNetMemberOwner;
2526
import consulo.language.psi.PsiElement;
2627
import consulo.language.psi.PsiFile;
@@ -31,8 +32,8 @@
3132
import consulo.ui.annotation.RequiredUIAccess;
3233
import consulo.ui.ex.tree.TreeHelper;
3334
import jakarta.inject.Inject;
34-
3535
import org.jspecify.annotations.Nullable;
36+
3637
import java.util.ArrayList;
3738
import java.util.Collection;
3839
import java.util.List;
@@ -42,64 +43,52 @@
4243
* @since 09.12.13.
4344
*/
4445
@ExtensionImpl
45-
public class CSharpProjectViewProvider implements SelectableTreeStructureProvider, DumbAware
46-
{
47-
private final Project myProject;
46+
public class CSharpProjectViewProvider implements SelectableTreeStructureProvider, DumbAware {
47+
private final Project myProject;
4848

49-
@Inject
50-
public CSharpProjectViewProvider(Project project)
51-
{
52-
myProject = project;
53-
}
49+
@Inject
50+
public CSharpProjectViewProvider(Project project) {
51+
myProject = project;
52+
}
5453

55-
@Nullable
56-
@Override
57-
public PsiElement getTopLevelElement(PsiElement element)
58-
{
59-
return element.getContainingFile();
60-
}
54+
@Nullable
55+
@Override
56+
public PsiElement getTopLevelElement(PsiElement element) {
57+
return element.getContainingFile();
58+
}
6159

62-
@Override
63-
@RequiredUIAccess
64-
public Collection<AbstractTreeNode> modify(AbstractTreeNode parent, Collection<AbstractTreeNode> oldNodes, ViewSettings settings)
65-
{
66-
return TreeHelper.calculateYieldingToWriteAction(() -> doModify(oldNodes, settings));
67-
}
60+
@Override
61+
@RequiredUIAccess
62+
public Collection<AbstractTreeNode> modify(AbstractTreeNode parent, Collection<AbstractTreeNode> oldNodes, ViewSettings settings) {
63+
return TreeHelper.calculateYieldingToWriteAction(() -> doModify(oldNodes, settings));
64+
}
6865

69-
@RequiredReadAction
70-
private List<AbstractTreeNode> doModify(Collection<AbstractTreeNode> oldNodes, ViewSettings settings)
71-
{
72-
List<AbstractTreeNode> nodes = new ArrayList<>(oldNodes.size());
73-
for(AbstractTreeNode treeNode : oldNodes)
74-
{
75-
ProgressManager.checkCanceled();
66+
@RequiredReadAction
67+
private List<AbstractTreeNode> doModify(Collection<AbstractTreeNode> oldNodes, ViewSettings settings) {
68+
List<AbstractTreeNode> nodes = new ArrayList<>(oldNodes.size());
69+
for (AbstractTreeNode treeNode : oldNodes) {
70+
ProgressManager.checkCanceled();
7671

77-
Object value = treeNode.getValue();
72+
Object value = treeNode.getValue();
7873

79-
if(value instanceof PsiFile)
80-
{
81-
for(CSharpProjectTreeNodeExpander expander : Application.get().getExtensionPoint(CSharpProjectTreeNodeExpander.class))
82-
{
83-
AbstractTreeNode<?> node = expander.expandFile(myProject, settings, treeNode);
84-
if(node != null)
85-
{
86-
nodes.add(node);
87-
break;
88-
}
89-
}
90-
}
91-
else
92-
{
93-
if(value instanceof DotNetMemberOwner)
94-
{
95-
nodes.add(new CSharpElementTreeNode((DotNetMemberOwner) value, settings, 0));
96-
}
97-
else
98-
{
99-
nodes.add(treeNode);
100-
}
101-
}
102-
}
103-
return nodes;
104-
}
74+
if (value instanceof PsiFile) {
75+
for (CSharpProjectTreeNodeExpander expander : Application.get().getExtensionPoint(CSharpProjectTreeNodeExpander.class)) {
76+
AbstractTreeNode<?> node = expander.expandFile(myProject, settings, treeNode);
77+
if (node != null) {
78+
nodes.add(node);
79+
break;
80+
}
81+
}
82+
}
83+
else {
84+
if (value instanceof DotNetMemberOwner) {
85+
nodes.add(new CSharpElementTreeNode((DotNetMemberOwner) value, settings, 0));
86+
}
87+
else {
88+
nodes.add(treeNode);
89+
}
90+
}
91+
}
92+
return nodes;
93+
}
10594
}

csharp-impl/src/main/java/consulo/csharp/impl/ide/projectView/impl/DefaultCSharpProjectTreeNodeExpander.java

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,60 +16,51 @@
1616

1717
package consulo.csharp.impl.ide.projectView.impl;
1818

19-
import consulo.annotation.component.ExtensionImpl;
20-
import consulo.project.ui.view.tree.ViewSettings;
21-
import consulo.project.ui.view.tree.AbstractTreeNode;
22-
import consulo.project.Project;
23-
import consulo.language.psi.PsiFile;
2419
import consulo.annotation.access.RequiredReadAction;
20+
import consulo.annotation.component.ExtensionImpl;
2521
import consulo.csharp.impl.ide.codeInsight.problems.CSharpLocationUtil;
2622
import consulo.csharp.impl.ide.projectView.CSharpElementTreeNode;
27-
import consulo.csharp.impl.ide.projectView.CSharpProjectTreeNodeExpander;
28-
import consulo.csharp.lang.psi.CSharpFile;
2923
import consulo.csharp.lang.impl.psi.source.CSharpDummyDeclarationImpl;
3024
import consulo.csharp.lang.impl.psi.source.CSharpPsiUtilImpl;
25+
import consulo.csharp.lang.psi.CSharpFile;
26+
import consulo.csharp.projectView.CSharpProjectTreeNodeExpander;
3127
import consulo.dotnet.psi.DotNetNamedElement;
32-
28+
import consulo.language.psi.PsiFile;
29+
import consulo.project.Project;
30+
import consulo.project.ui.view.tree.AbstractTreeNode;
31+
import consulo.project.ui.view.tree.ViewSettings;
3332
import org.jspecify.annotations.Nullable;
3433

3534
/**
3635
* @author VISTALL
3736
* @since 2020-10-28
3837
*/
3938
@ExtensionImpl
40-
public class DefaultCSharpProjectTreeNodeExpander implements CSharpProjectTreeNodeExpander
41-
{
42-
@RequiredReadAction
43-
@Nullable
44-
@Override
45-
public AbstractTreeNode<?> expandFile(Project project, ViewSettings settings, AbstractTreeNode<?> treeNode)
46-
{
47-
Object value = treeNode.getValue();
39+
public class DefaultCSharpProjectTreeNodeExpander implements CSharpProjectTreeNodeExpander {
40+
@RequiredReadAction
41+
@Nullable
42+
@Override
43+
public AbstractTreeNode<?> expandFile(Project project, ViewSettings settings, AbstractTreeNode<?> treeNode) {
44+
Object value = treeNode.getValue();
4845

49-
if(value instanceof PsiFile)
50-
{
51-
CSharpFile file = CSharpPsiUtilImpl.findCSharpFile((PsiFile) value);
52-
if(file != null)
53-
{
54-
if(CSharpLocationUtil.isValidLocation(project, ((PsiFile) value).getVirtualFile()))
55-
{
56-
DotNetNamedElement singleElement = CSharpPsiUtilImpl.findSingleElementNoNameCheck(file);
57-
if(singleElement instanceof CSharpDummyDeclarationImpl)
58-
{
59-
return new CSharpElementTreeNode(file, settings, 0);
60-
}
61-
else if(singleElement != null)
62-
{
63-
return new CSharpElementTreeNode(singleElement, settings, CSharpElementTreeNode.ALLOW_GRAY_FILE_NAME);
64-
}
65-
else
66-
{
67-
return new CSharpElementTreeNode(file, settings, CSharpElementTreeNode.FORCE_EXPAND);
68-
}
69-
}
70-
}
71-
}
46+
if (value instanceof PsiFile) {
47+
CSharpFile file = CSharpPsiUtilImpl.findCSharpFile((PsiFile) value);
48+
if (file != null) {
49+
if (CSharpLocationUtil.isValidLocation(project, ((PsiFile) value).getVirtualFile())) {
50+
DotNetNamedElement singleElement = CSharpPsiUtilImpl.findSingleElementNoNameCheck(file);
51+
if (singleElement instanceof CSharpDummyDeclarationImpl) {
52+
return new CSharpElementTreeNode(file, settings, 0);
53+
}
54+
else if (singleElement != null) {
55+
return new CSharpElementTreeNode(singleElement, settings, CSharpElementTreeNode.ALLOW_GRAY_FILE_NAME);
56+
}
57+
else {
58+
return new CSharpElementTreeNode(file, settings, CSharpElementTreeNode.FORCE_EXPAND);
59+
}
60+
}
61+
}
62+
}
7263

73-
return treeNode;
74-
}
64+
return treeNode;
65+
}
7566
}

csharp-impl/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
requires transitive consulo.csharp.doc.psi.impl;
2222
requires transitive consulo.internal.dotnet.asm;
2323
requires transitive consulo.internal.dotnet.msil.decompiler;
24+
requires transitive consulo.csharp.project.view.api;
2425

2526
exports consulo.csharp.impl.compiler;
2627
exports consulo.csharp.impl.ide;

csharp-project-view-api/pom.xml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
- Copyright 2013-2026 consulo.io
5+
-
6+
- Licensed under the Apache License, Version 2.0 (the "License");
7+
- you may not use this file except in compliance with the License.
8+
- You may obtain a copy of the License at
9+
-
10+
- http://www.apache.org/licenses/LICENSE-2.0
11+
-
12+
- Unless required by applicable law or agreed to in writing, software
13+
- distributed under the License is distributed on an "AS IS" BASIS,
14+
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
- See the License for the specific language governing permissions and
16+
- limitations under the License.
17+
-->
18+
19+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<parent>
24+
<groupId>consulo</groupId>
25+
<artifactId>arch.bind.java</artifactId>
26+
<version>3-SNAPSHOT</version>
27+
<relativePath/>
28+
</parent>
29+
30+
<repositories>
31+
<repository>
32+
<id>consulo</id>
33+
<url>https://maven.consulo.dev/repository/snapshots/</url>
34+
<snapshots>
35+
<enabled>true</enabled>
36+
<updatePolicy>interval:60</updatePolicy>
37+
</snapshots>
38+
</repository>
39+
</repositories>
40+
41+
<groupId>consulo.plugin</groupId>
42+
<artifactId>consulo.csharp.project.view.api</artifactId>
43+
<version>3-SNAPSHOT</version>
44+
<packaging>jar</packaging>
45+
46+
<dependencies>
47+
<dependency>
48+
<groupId>${project.groupId}</groupId>
49+
<artifactId>consulo.csharp-csharp.api</artifactId>
50+
<version>${project.version}</version>
51+
</dependency>
52+
<dependency>
53+
<groupId>${project.groupId}</groupId>
54+
<artifactId>consulo.csharp-csharp.psi.api</artifactId>
55+
<version>${project.version}</version>
56+
</dependency>
57+
</dependencies>
58+
</project>

csharp-impl/src/main/java/consulo/csharp/impl/ide/projectView/CSharpProjectTreeNodeExpander.java renamed to csharp-project-view-api/src/main/java/consulo/csharp/projectView/CSharpProjectTreeNodeExpander.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,23 @@
1414
* limitations under the License.
1515
*/
1616

17-
package consulo.csharp.impl.ide.projectView;
17+
package consulo.csharp.projectView;
1818

1919
import consulo.annotation.access.RequiredReadAction;
2020
import consulo.annotation.component.ComponentScope;
2121
import consulo.annotation.component.ExtensionAPI;
2222
import consulo.project.Project;
2323
import consulo.project.ui.view.tree.AbstractTreeNode;
2424
import consulo.project.ui.view.tree.ViewSettings;
25-
2625
import org.jspecify.annotations.Nullable;
2726

2827
/**
2928
* @author VISTALL
3029
* @since 2020-10-28
3130
*/
3231
@ExtensionAPI(ComponentScope.APPLICATION)
33-
public interface CSharpProjectTreeNodeExpander
34-
{
35-
@Nullable
36-
@RequiredReadAction
37-
AbstractTreeNode<?> expandFile(Project project, ViewSettings viewSettings, AbstractTreeNode<?> originalNode);
32+
public interface CSharpProjectTreeNodeExpander {
33+
@Nullable
34+
@RequiredReadAction
35+
AbstractTreeNode<?> expandFile(Project project, ViewSettings viewSettings, AbstractTreeNode<?> originalNode);
3836
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* @author VISTALL
3+
* @since 2026-04-12
4+
*/
5+
module consulo.csharp.project.view.api {
6+
requires consulo.csharp.api;
7+
requires consulo.project.ui.view.api;
8+
9+
exports consulo.csharp.projectView;
10+
}

csharp-psi-impl/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@
8484
<artifactId>consulo.csharp-csharp-composite.formatting.string.api</artifactId>
8585
<version>${project.version}</version>
8686
</dependency>
87+
<dependency>
88+
<groupId>${project.groupId}</groupId>
89+
<artifactId>consulo.csharp.project.view.api</artifactId>
90+
<version>${project.version}</version>
91+
</dependency>
8792
<dependency>
8893
<groupId>consulo.internal</groupId>
8994
<artifactId>gnu.jel</artifactId>

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<modules>
4545
<module>csharp-api</module>
4646
<module>csharp-editor-api</module>
47+
<module>csharp-project-view-api</module>
4748
<module>csharp-psi-api</module>
4849
<module>csharp-psi-impl</module>
4950
<module>csharp-doc-psi-api</module>

0 commit comments

Comments
 (0)