From bca53cf4ef613e757aa9c7e093a831d37d53861e Mon Sep 17 00:00:00 2001
From: Peter Broadbery
Date: Sat, 3 Mar 2018 09:26:17 +0000
Subject: [PATCH] Flat tree structure, fixes
---
.idea/misc.xml | 2 +-
.idea/shelf/Initial_attempt_at_psiSubs.xml | 4 +
build.gradle | 6 +-
resources/META-INF/plugin.xml | 32 +++-
.../build/module/AldorBuildLocationForm.form | 36 ++++
.../build/module/AldorBuildLocationForm.java | 8 +
.../AldorModuleConfigEditorProvider.java | 28 ++-
.../AldorCompletionContributor.java | 3 +-
.../AbstractChangeHierarchyViewAction.java | 53 ++++++
.../AldorFlatHierarchyTreeStructure.java | 119 ++++++++++++
.../AldorHierarchyNodeDescriptor.java | 6 +-
.../AldorHierarchyOperationDescriptor.java | 7 +-
.../AldorMissingHierarchyProvider.java | 44 +++++
...rParentCategoryHierarchyTreeStructure.java | 19 +-
.../hierarchy/AldorTypeHierarchyBrowser.java | 90 ++++++---
.../hierarchy/AldorTypeHierarchyProvider.java | 7 +-
.../aldor/hierarchy/ComparatorPriority.java | 7 +
.../aldor/hierarchy/ErrorNodeDescriptor.java | 11 +-
.../hierarchy/ViewFlatHierarchyAction.java | 17 ++
.../hierarchy/ViewParentHierarchyAction.java | 16 ++
.../template/AldorGitModuleBuilder.java | 129 ++++++++++---
.../template/AldorGitTemplateFactory.java | 4 +-
.../module/template/WizardTextField.java | 76 ++++++--
.../psi/stub/codec/AldorDeclareStubCodec.java | 8 +-
src/main/java/aldor/sdk/AldorSdkType.java | 4 +-
src/main/java/aldor/sdk/AxiomSdk.java | 5 +
src/main/java/aldor/sdk/FricasSdkType.java | 4 +-
.../{FricasSdkTypes.java => SdkTypes.java} | 8 +-
.../java/aldor/spad/FricasSpadLibrary.java | 175 +++++++++++++++---
.../aldor/spad/FricasSpadLibraryBuilder.java | 49 +++++
.../java/aldor/spad/SpadLibraryManager.java | 43 ++++-
.../SpadInputRunConfigurationType.java | 6 +-
src/main/java/aldor/ui/AldorActions.java | 5 +
src/main/java/aldor/util/Assertions.java | 12 ++
.../AldorCompletionContributorTest.java | 15 +-
...dorTypeHierarchyBrowserMissingLibTest.java | 36 ++--
.../AldorTypeHierarchyBrowserTest.java | 38 ++++
.../psi/index/AldorDefineNameIndexTest.java | 2 +-
.../spad/FricasLocalSpadLibraryTest.java | 56 ++++++
.../aldor/spad/FricasSpadLibraryTest.java | 27 ++-
.../spad/SpadLibraryManagerDistSdkTest.java | 37 ++++
.../spad/SpadLibraryManagerLocalSdkTest.java | 36 ++++
.../aldor/spad/SpadLibraryManagerTest.java | 30 +--
src/test/java/aldor/syntax/SyntaxTest.java | 4 +-
.../test_util/SdkProjectDescriptors.java | 42 ++++-
45 files changed, 1165 insertions(+), 201 deletions(-)
create mode 100644 .idea/shelf/Initial_attempt_at_psiSubs.xml
create mode 100644 src/main/java/aldor/build/module/AldorBuildLocationForm.form
create mode 100644 src/main/java/aldor/build/module/AldorBuildLocationForm.java
create mode 100644 src/main/java/aldor/hierarchy/AbstractChangeHierarchyViewAction.java
create mode 100644 src/main/java/aldor/hierarchy/AldorFlatHierarchyTreeStructure.java
create mode 100644 src/main/java/aldor/hierarchy/AldorMissingHierarchyProvider.java
create mode 100644 src/main/java/aldor/hierarchy/ComparatorPriority.java
create mode 100644 src/main/java/aldor/hierarchy/ViewFlatHierarchyAction.java
create mode 100644 src/main/java/aldor/hierarchy/ViewParentHierarchyAction.java
create mode 100644 src/main/java/aldor/sdk/AxiomSdk.java
rename src/main/java/aldor/sdk/{FricasSdkTypes.java => SdkTypes.java} (53%)
create mode 100644 src/main/java/aldor/spad/FricasSpadLibraryBuilder.java
create mode 100644 src/main/java/aldor/ui/AldorActions.java
create mode 100644 src/main/java/aldor/util/Assertions.java
create mode 100644 src/test/java/aldor/spad/FricasLocalSpadLibraryTest.java
create mode 100644 src/test/java/aldor/spad/SpadLibraryManagerDistSdkTest.java
create mode 100644 src/test/java/aldor/spad/SpadLibraryManagerLocalSdkTest.java
diff --git a/.idea/misc.xml b/.idea/misc.xml
index ca492c2..9fa41d4 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/.idea/shelf/Initial_attempt_at_psiSubs.xml b/.idea/shelf/Initial_attempt_at_psiSubs.xml
new file mode 100644
index 0000000..aed1329
--- /dev/null
+++ b/.idea/shelf/Initial_attempt_at_psiSubs.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 3bc72b4..49597f4 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,5 +1,5 @@
plugins {
- id 'org.jetbrains.intellij' version "0.2.5"
+ id 'org.jetbrains.intellij' version "0.2.7"
id "de.undercouch.download" version "3.2.0"
}
@@ -7,7 +7,7 @@ plugins {
allprojects {
apply plugin: 'java'
group = 'org.aldor.idea'
- version = '1.0'
+ version = '1.1'
sourceSets {
main.java.srcDirs = ['src/main/java', 'src/gen/jflex', 'src/gen/grammar']
@@ -22,7 +22,7 @@ allprojects {
plugins = []
- //updateSinceUntilBuild = false// Was in haskell, but..
+ updateSinceUntilBuild = false// Was in haskell, but..
sandboxDirectory = project.rootDir.canonicalPath + "/.sandbox"
}
diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml
index ec002f4..9bdf99a 100644
--- a/resources/META-INF/plugin.xml
+++ b/resources/META-INF/plugin.xml
@@ -1,21 +1,21 @@
-
+
pab.aldor
Aldor Plugin
- 1.0
- Peter Broadbery
+ 1.1
+ Peter Broadbery
-
+
@@ -84,6 +84,7 @@
+
@@ -108,6 +109,27 @@
text="Create New SPAD File" description="Creates a new SPAD file">
+
+
+
+
diff --git a/src/main/java/aldor/build/module/AldorBuildLocationForm.form b/src/main/java/aldor/build/module/AldorBuildLocationForm.form
new file mode 100644
index 0000000..c358352
--- /dev/null
+++ b/src/main/java/aldor/build/module/AldorBuildLocationForm.form
@@ -0,0 +1,36 @@
+
+
diff --git a/src/main/java/aldor/build/module/AldorBuildLocationForm.java b/src/main/java/aldor/build/module/AldorBuildLocationForm.java
new file mode 100644
index 0000000..641abbe
--- /dev/null
+++ b/src/main/java/aldor/build/module/AldorBuildLocationForm.java
@@ -0,0 +1,8 @@
+package aldor.build.module;
+
+import javax.swing.JComponent;
+import javax.swing.JTextField;
+
+public class AldorBuildLocationForm extends JComponent {
+ private JTextField buildDirectory;
+}
diff --git a/src/main/java/aldor/build/module/AldorModuleConfigEditorProvider.java b/src/main/java/aldor/build/module/AldorModuleConfigEditorProvider.java
index 68f6415..24c3065 100644
--- a/src/main/java/aldor/build/module/AldorModuleConfigEditorProvider.java
+++ b/src/main/java/aldor/build/module/AldorModuleConfigEditorProvider.java
@@ -47,7 +47,7 @@ public static class OutputDirectoryEditor extends ModuleElementsEditor {
public OutputDirectoryEditor(ModuleConfigurationState state) {
super(state);
- outputEditor = new AldorBuildElementsEditor(state);
+ outputEditor = new AldorBuildPathEditor(state);
}
@Override
@@ -73,13 +73,35 @@ public String getHelpTopic() {
}
}
- private static class AldorBuildElementsEditor extends BuildElementsEditor {
+ private static class AldorBuildPathEditor extends BuildElementsEditor {
- protected AldorBuildElementsEditor(ModuleConfigurationState state) {
+ protected AldorBuildPathEditor(ModuleConfigurationState state) {
super(state);
}
}
+ /* Giving up and using the output editor instead.
+ * Would be nice to have a custom editor
+
+ private static class LocalBuildElementsEditor extends ModuleElementsEditor {
+ AldorBuildLocationForm locationForm = new AldorBuildLocationForm();
+ protected LocalBuildElementsEditor(@NotNull ModuleConfigurationState state) {
+ super(state);
+ }
+
+ @Override
+ protected JComponent createComponentImpl() {
+ return locationForm;
+ }
+
+ @Nls
+ @Override
+ public String getDisplayName() {
+ return "Local Build Location";
+ }
+
+ }
+ */
/**
* Classpath editor tweaked to hide class path boxes (keeps the module setting)
*/
diff --git a/src/main/java/aldor/editor/completion/AldorCompletionContributor.java b/src/main/java/aldor/editor/completion/AldorCompletionContributor.java
index 5d4adcd..74265f2 100644
--- a/src/main/java/aldor/editor/completion/AldorCompletionContributor.java
+++ b/src/main/java/aldor/editor/completion/AldorCompletionContributor.java
@@ -28,6 +28,7 @@
import com.intellij.util.ProcessingContext;
import org.jetbrains.annotations.NotNull;
+import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -64,7 +65,7 @@ protected void addCompletions(@NotNull CompletionParameters parameters,
public List allTypes(CompletionParameters parameters) {
PsiElement elt = parameters.getPosition();
SpadLibrary spadLibrary = SpadLibraryManager.instance().spadLibraryForElement(elt);
- return allTypes(spadLibrary);
+ return (spadLibrary == null) ? Collections.emptyList() : allTypes(spadLibrary);
}
@VisibleForTesting
diff --git a/src/main/java/aldor/hierarchy/AbstractChangeHierarchyViewAction.java b/src/main/java/aldor/hierarchy/AbstractChangeHierarchyViewAction.java
new file mode 100644
index 0000000..b932e95
--- /dev/null
+++ b/src/main/java/aldor/hierarchy/AbstractChangeHierarchyViewAction.java
@@ -0,0 +1,53 @@
+package aldor.hierarchy;
+
+import com.intellij.ide.hierarchy.TypeHierarchyBrowserBase;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.DataContext;
+import com.intellij.openapi.actionSystem.Presentation;
+import com.intellij.openapi.actionSystem.ToggleAction;
+import com.intellij.openapi.application.ApplicationManager;
+import org.jetbrains.annotations.NotNull;
+
+import javax.swing.Icon;
+
+public abstract class AbstractChangeHierarchyViewAction extends ToggleAction {
+
+ AbstractChangeHierarchyViewAction(final String shortDescription, final String longDescription, final Icon icon) {
+ super(shortDescription, longDescription, icon);
+ }
+
+ @Override
+ public final boolean isSelected(final AnActionEvent event) {
+ final AldorTypeHierarchyBrowser browser = (AldorTypeHierarchyBrowser) getTypeHierarchyBrowser(event.getDataContext());
+ return (browser != null) && getTypeName().equals(browser.typeName());
+ }
+
+ protected abstract String getTypeName();
+
+ @Override
+ public final void setSelected(final AnActionEvent event, final boolean flag) {
+ if (flag) {
+ final TypeHierarchyBrowserBase browser = getTypeHierarchyBrowser(event.getDataContext());
+ // setWaitCursor();
+ ApplicationManager.getApplication().invokeLater(() -> {
+ if (browser != null) {
+ browser.changeView(getTypeName());
+ }
+ });
+ }
+ }
+
+ @Override
+ public void update(@NotNull final AnActionEvent event) {
+ // its important to assign the myTypeHierarchyBrowser first
+ super.update(event);
+ final Presentation presentation = event.getPresentation();
+ presentation.setEnabled(true);
+ }
+
+ static TypeHierarchyBrowserBase getTypeHierarchyBrowser(final DataContext context) {
+ return TypeHierarchyBrowserBase.DATA_KEY.getData(context);
+ }
+
+
+}
diff --git a/src/main/java/aldor/hierarchy/AldorFlatHierarchyTreeStructure.java b/src/main/java/aldor/hierarchy/AldorFlatHierarchyTreeStructure.java
new file mode 100644
index 0000000..4ae89ba
--- /dev/null
+++ b/src/main/java/aldor/hierarchy/AldorFlatHierarchyTreeStructure.java
@@ -0,0 +1,119 @@
+package aldor.hierarchy;
+
+import aldor.spad.SpadLibrary;
+import aldor.spad.SpadLibraryManager;
+import aldor.syntax.Syntax;
+import aldor.syntax.SyntaxPrinter;
+import aldor.syntax.SyntaxUtils;
+import com.intellij.ide.hierarchy.HierarchyNodeDescriptor;
+import com.intellij.ide.hierarchy.HierarchyTreeStructure;
+import com.intellij.ide.util.treeView.NodeDescriptor;
+import com.intellij.openapi.project.Project;
+import com.intellij.psi.PsiElement;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Deque;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static aldor.syntax.SyntaxUtils.psiElementFromSyntax;
+
+public class AldorFlatHierarchyTreeStructure extends HierarchyTreeStructure {
+ private static final Object[] EMPTY_ARRAY = new Object[0];
+ //private final SmartPsiElementPointer smartPointer;
+
+ public AldorFlatHierarchyTreeStructure(Project project, @NotNull Syntax syntax) {
+ super(project, createBaseNodeDescriptor(project, syntax));
+ //this.smartPointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(psiElementFromSyntax(syntax));
+ }
+
+ private static HierarchyNodeDescriptor createBaseNodeDescriptor(Project project, @NotNull Syntax syntax) {
+ return new AldorHierarchyNodeDescriptor(project, null, psiElementFromSyntax(syntax), syntax, true);
+ }
+
+ @Override
+ public boolean isAlwaysLeaf(Object element) {
+ if (!(element instanceof HierarchyNodeDescriptor)) {
+ return true;
+ }
+ HierarchyNodeDescriptor descriptor = (HierarchyNodeDescriptor) element;
+ if (descriptor instanceof ErrorNodeDescriptor) {
+ return true;
+ }
+ if (descriptor.getParentDescriptor() != null) {
+ return true;
+ }
+ return false;
+ }
+
+ @NotNull
+ @Override
+ protected Object[] buildChildren(@NotNull HierarchyNodeDescriptor descriptor) {
+ if (descriptor instanceof ErrorNodeDescriptor) {
+ return EMPTY_ARRAY;
+ }
+ if (descriptor.getParentDescriptor() != null) {
+ return EMPTY_ARRAY;
+ }
+
+ AldorHierarchyNodeDescriptor nodeDescriptor = (AldorHierarchyNodeDescriptor) descriptor;
+ SpadLibrary library = SpadLibraryManager.instance().spadLibraryForElement(descriptor.getPsiElement());
+ if (library == null) {
+ return new Object[] { "Missing library"};
+ }
+ Syntax syntax = nodeDescriptor.syntax();
+ List parents = this.parents(library, syntax);
+ //noinspection ObjectEquality
+ assert parents.get(0) == syntax;
+ List operations = this.operations(library, parents);
+
+ Stream