Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structure View #243

Merged
merged 39 commits into from
Feb 25, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
00a10fa
Module structure view
KronicDeth Jan 21, 2016
c7525c9
Kernel.def/2 structure view
KronicDeth Jan 23, 2016
cacd8c6
Group function clauses together in Structure View
KronicDeth Jan 24, 2016
23adbcf
defdelegate structure view
KronicDeth Jan 26, 2016
20f0a57
Fix tests after removal of NoParenthesesExpression
KronicDeth Jan 27, 2016
6ff7cbd
Optimize imports
KronicDeth Jan 27, 2016
67c0e2a
Fix ambiguous_op quoting by skiping identifier element
KronicDeth Jan 27, 2016
62c12cd
Compress implements and methods for InfixOperation
KronicDeth Jan 28, 2016
4b6320b
Handle operations for `def/2` names
KronicDeth Jan 30, 2016
48547b5
Group callbacks under defexception
KronicDeth Jan 31, 2016
eb22a14
Always show default values for exception fields
KronicDeth Feb 1, 2016
7223cd1
defimpl structure view
KronicDeth Feb 2, 2016
ae8fda8
defmacro in structure
KronicDeth Feb 3, 2016
6b9fd78
Collapse Function and Macro structure view
KronicDeth Feb 5, 2016
0897759
Time sort
KronicDeth Feb 6, 2016
7a7f353
Fake new RowIcon(Icon... icon) with factory
KronicDeth Feb 6, 2016
0b5d686
defp and defmacrop structure
KronicDeth Feb 6, 2016
821f40e
Visibility sorter
KronicDeth Feb 6, 2016
cbcf038
Show structure inside of quote calls
KronicDeth Feb 7, 2016
c835a82
defoverridable structure
KronicDeth Feb 8, 2016
00a1bd8
Mark function CallDefinition as overridable
KronicDeth Feb 9, 2016
df5829d
`use` in Structure
KronicDeth Feb 9, 2016
41ff2c6
Default arguments generate entry for each arity
KronicDeth Feb 13, 2016
1a9415f
Provide __using__ quote's function to use location
KronicDeth Feb 15, 2016
5e5abb2
Show "use <ALIAS>" for location of injected functions
KronicDeth Feb 15, 2016
d5d3dde
Mark function overrides for use overriddable functions
KronicDeth Feb 17, 2016
202c156
Remove unused import that fails on travis-ci
KronicDeth Feb 17, 2016
3f7f02b
Callbacks using implemented method icon
KronicDeth Feb 20, 2016
6b892fc
@spec in structure view
KronicDeth Feb 20, 2016
8d8871a
Use NameArity for callback presentation
KronicDeth Feb 21, 2016
1d4b939
Callbacks split into name/arity and spec
KronicDeth Feb 21, 2016
6d62b16
Fix case-sensitive naming
KronicDeth Feb 22, 2016
b0731c6
@type, @typep and @opaque in Structure
KronicDeth Feb 22, 2016
6116b4b
defprotocol in Structure
KronicDeth Feb 22, 2016
935ba90
Structure with defstruct and its fields
KronicDeth Feb 23, 2016
5d2a393
Qualified alias support for defimpl
KronicDeth Feb 23, 2016
b236449
Fix Scroll From Source
KronicDeth Feb 24, 2016
ea00323
Better Scroll From Source
KronicDeth Feb 24, 2016
f693070
Show implicit Structure for Exception
KronicDeth Feb 24, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
defp and defmacrop structure
Includes generic support for visibility on call definitions and call
definition clauses.
  • Loading branch information
KronicDeth committed Feb 22, 2016
commit 0b5d686335bdb787633ab50f4b2e6cb03bae1d93
23 changes: 17 additions & 6 deletions src/org/elixir_lang/icons/ElixirIcons.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,28 @@ public static RowIcon create(Icon... icons) {
* Created by zyuyou on 15/7/6.
*/
public interface ElixirIcons {

interface Time {
Icon COMPILE = AllIcons.Actions.Compile;
Icon RUN = AllIcons.General.Run;
}

interface Visibility {
Icon PRIVATE = PlatformIcons.PRIVATE_ICON;
Icon PUBLIC = PlatformIcons.PUBLIC_ICON;
}

Icon CALL_DEFINITION = PlatformIcons.FUNCTION_ICON;
Icon CALL_DEFINITION_CLAUSE = RowIconFactory.create(CALL_DEFINITION, PlatformIcons.PACKAGE_LOCAL_ICON);
Icon DELEGATION = RowIconFactory.create(AllIcons.General.Run, PlatformIcons.PACKAGE_LOCAL_ICON);
Icon EXCEPTION = PlatformIcons.EXCEPTION_CLASS_ICON;
Icon FILE = IconLoader.getIcon("/icons/elixir-16.png");
Icon FUNCTION = RowIconFactory.create(AllIcons.General.Run, PlatformIcons.FUNCTION_ICON);
Icon FUNCTION_CLAUSE = RowIconFactory.create(FUNCTION, PlatformIcons.PACKAGE_LOCAL_ICON);
Icon FUNCTION_DELEGATION = FUNCTION_CLAUSE;
Icon MACRO = RowIconFactory.create(AllIcons.Actions.Compile, PlatformIcons.FUNCTION_ICON);
Icon MACRO_CLAUSE = RowIconFactory.create(MACRO, PlatformIcons.PACKAGE_LOCAL_ICON);
Icon IMPLEMENTATION = PlatformIcons.ANONYMOUS_CLASS_ICON;
Icon MIX_MODULE_CONFLICT = AllIcons.Actions.Cancel;
Icon MODULE = PlatformIcons.PACKAGE_ICON;
Icon IMPLEMENTATION = PlatformIcons.ANONYMOUS_CLASS_ICON;

// it is the unknown that is only a question mark
Icon UNKNOWN = AllIcons.RunConfigurations.Unknown;

Icon ELIXIR_APPLICATION = IconLoader.getIcon("/icons/elixir-Application-16.png");
Icon ELIXIR_SUPERVISOR = IconLoader.getIcon("/icons/elixir-Supervisor-16.png");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import com.intellij.util.PlatformIcons;
import org.elixir_lang.icons.ElixirIcons;
import org.elixir_lang.structure_view.element.Timed;
import org.elixir_lang.structure_view.element.Visible;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

Expand All @@ -21,15 +23,27 @@ public class CallDefinition implements ItemPresentation {
private final Parent parent;
@NotNull
private final Timed.Time time;
@Nullable
private final Visible.Visibility visibility;

/**
*
* @param parent
* @param time
* @param visibility {@code null} if clauses are a mix of private and public
* @param name
* @param arity
*/
public CallDefinition(@NotNull Parent parent,
@NotNull Timed.Time time,
@Nullable Visible.Visibility visibility,
@NotNull String name,
int arity) {
this.arity = arity;
this.name = name;
this.parent = parent;
this.time = time;
this.visibility = visibility;
}

/**
Expand Down Expand Up @@ -63,22 +77,36 @@ public String getLocationString() {
@NotNull
@Override
public Icon getIcon(boolean unused) {
RowIcon rowIcon = new RowIcon(2);
RowIcon rowIcon = new RowIcon(3);
Icon timeIcon = null;

switch (time) {
case COMPILE:
timeIcon = ElixirIcons.MACRO;
timeIcon = ElixirIcons.Time.COMPILE;
break;
case RUN:
timeIcon = ElixirIcons.FUNCTION;
timeIcon = ElixirIcons.Time.RUN;
break;
}

assert timeIcon != null;

Icon visibilityIcon = null;

switch (visibility) {
case PRIVATE:
visibilityIcon = ElixirIcons.Visibility.PRIVATE;
break;
case PUBLIC:
visibilityIcon = ElixirIcons.Visibility.PUBLIC;
break;
default:
visibilityIcon = ElixirIcons.UNKNOWN;
}

rowIcon.setIcon(timeIcon, 0);
rowIcon.setIcon(PlatformIcons.PUBLIC_ICON, 1);
rowIcon.setIcon(visibilityIcon, 1);
rowIcon.setIcon(ElixirIcons.CALL_DEFINITION, 2);

return rowIcon;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.intellij.util.PlatformIcons;
import org.elixir_lang.icons.ElixirIcons;
import org.elixir_lang.psi.call.Call;
import org.elixir_lang.structure_view.element.Visible;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -18,6 +19,7 @@ public class CallDefinitionClause implements ItemPresentation {

private final Call call;
private final CallDefinition callDefinition;
private final Visible.Visibility visibility;

/*
* Constructors
Expand All @@ -28,9 +30,12 @@ public class CallDefinitionClause implements ItemPresentation {
* @param call a {@code Kernel.def/2} call nested in {@code parent}
* @param callDefinition the parent {@link CallDefinition} of which {@code call} is a clause
*/
public CallDefinitionClause(@NotNull CallDefinition callDefinition, @NotNull Call call) {
public CallDefinitionClause(@NotNull CallDefinition callDefinition,
@NotNull Visible.Visibility visibility,
@NotNull Call call) {
this.call = call;
this.callDefinition = callDefinition;
this.visibility = visibility;
}

/*
Expand Down Expand Up @@ -73,22 +78,36 @@ public String getLocationString() {
@Nullable
@Override
public Icon getIcon(boolean unused) {
RowIcon rowIcon = new RowIcon(2);
RowIcon rowIcon = new RowIcon(3);
Icon timeIcon = null;

switch (callDefinition.time()) {
case COMPILE:
timeIcon = ElixirIcons.MACRO_CLAUSE;
timeIcon = ElixirIcons.Time.COMPILE;
break;
case RUN:
timeIcon = ElixirIcons.FUNCTION_CLAUSE;
timeIcon = ElixirIcons.Time.RUN;
break;
}

assert timeIcon != null;

Icon visibilityIcon = null;

switch (visibility) {
case PRIVATE:
visibilityIcon = ElixirIcons.Visibility.PRIVATE;
break;
case PUBLIC:
visibilityIcon = ElixirIcons.Visibility.PUBLIC;
break;
}

assert visibilityIcon != null;

rowIcon.setIcon(timeIcon, 0);
rowIcon.setIcon(PlatformIcons.PUBLIC_ICON, 1);
rowIcon.setIcon(visibilityIcon, 1);
rowIcon.setIcon(ElixirIcons.CALL_DEFINITION_CLAUSE, 2);

return rowIcon;
}
Expand Down
66 changes: 0 additions & 66 deletions src/org/elixir_lang/navigation/item_presentation/Function.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.intellij.navigation.ItemPresentation;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.RowIcon;
import org.elixir_lang.icons.ElixirIcons;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -112,7 +113,14 @@ public String getLocationString() {
@Nullable
@Override
public Icon getIcon(boolean unused) {
return ElixirIcons.FUNCTION_DELEGATION;
RowIcon rowIcon = new RowIcon(3);

// same as {@code def}
rowIcon.setIcon(ElixirIcons.Time.RUN, 0);
rowIcon.setIcon(ElixirIcons.Visibility.PUBLIC, 1);
rowIcon.setIcon(ElixirIcons.CALL_DEFINITION_CLAUSE, 2);

return rowIcon;
}

public String name() {
Expand Down
42 changes: 41 additions & 1 deletion src/org/elixir_lang/structure_view/element/CallDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
import org.elixir_lang.navigation.item_presentation.Parent;
import org.elixir_lang.psi.call.Call;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

/**
* A definition for a call: either a function or a macro
*/
public class CallDefinition implements StructureViewTreeElement, Timed {
public class CallDefinition implements StructureViewTreeElement, Timed, Visible {
/*
* Enums
*/
Expand Down Expand Up @@ -129,6 +130,7 @@ public ItemPresentation getPresentation() {
return new org.elixir_lang.navigation.item_presentation.CallDefinition(
(Parent) module.getPresentation(),
time,
visibility(),
name,
arity
);
Expand Down Expand Up @@ -164,4 +166,42 @@ public Time time() {
return time;
}

/**
* The visibility of the element.
*
* @return {@link Visibility.PUBLIC} for public call definitions ({@code def} and {@code defmacro});
* {@link Visibility.PRIVATE} for private call definitions ({@code defp} and {@code defmacrop}); {@code null} for
* a mix of visibilities, such as when a call definition has a mix of call definition clause visibilities, which
* is invalid code, but can occur temporarily while code is being edited.
*/
@Nullable
@Override
public Visibility visibility() {

int privateCount = 0;
int publicCount = 0;

for (CallDefinitionClause callDefinitionClause : clauses) {
switch (callDefinitionClause.visibility()) {
case PRIVATE:
privateCount++;
break;
case PUBLIC:
publicCount++;
break;
}
}

Visibility callDefinitionVisibility;

if (privateCount > 0 && publicCount == 0) {
callDefinitionVisibility = Visibility.PRIVATE;
} else if (privateCount == 0 && publicCount > 0) {
callDefinitionVisibility = Visibility.PUBLIC;
} else {
callDefinitionVisibility = null;
}

return callDefinitionVisibility;
}
}
Loading