Skip to content

Commit

Permalink
fix: nodes not shown with disabling categories.
Browse files Browse the repository at this point in the history
With IntelliJ 2021 getEnabledCategories() is not working as thought
  • Loading branch information
u215942 committed Jun 11, 2021
1 parent fb6f6de commit 8710543
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 31 deletions.
9 changes: 6 additions & 3 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<idea-plugin version="2">
<id>ch.docksnet.rgraph</id>
<name>Java Method Reference Diagram</name>
<version>3.0.1</version>
<version>3.1.0</version>
<vendor>Stefan Zeller</vendor>
<depends>com.intellij.diagram</depends>
<depends>com.intellij.modules.java</depends>
Expand All @@ -44,7 +44,10 @@
<change-notes><![CDATA[
<ul>
<li>
Version 3.0.1: IntelliJ 2021.1+ support
Version 3.1.0: IntelliJ 2021.1+ support
<p>
Known Issue: Toolbar is partially not working. See <pre>https://github.com/Stefku/intellij-reference-diagram/issues/72</pre>.
</p>
</li>
<li>
Version 3.0.0
Expand Down Expand Up @@ -96,7 +99,7 @@
]]>
</change-notes>

<idea-version since-build="191"/>
<idea-version since-build="211.6085.26"/>

<application-components>
</application-components>
Expand Down
8 changes: 4 additions & 4 deletions src/ch/docksnet/rgraph/LCOMConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@
/**
* @author Stefan Zeller
*/
public class LCOMConverter {
class LCOMConverter {

private final ReferenceDiagramVfsResolver vfsResolver = new ReferenceDiagramVfsResolver();
private final Map<String, LCOMNode> lcomNodeRegistry = new HashMap<>();

/**
* Returns nodes representating a directed graph regarding to given {@code nodes} and {@code edges}.
*/
public Collection<LCOMNode> convert(Collection<? extends DiagramNode<PsiElement>> nodes, Collection<? extends
Collection<LCOMNode> convert(Collection<? extends DiagramNode<PsiElement>> nodes, Collection<? extends
DiagramEdge<PsiElement>> edges) {
for (DiagramNode<PsiElement> node : nodes) {
String fqn = this.vfsResolver.getQualifiedName(node.getIdentifyingElement());
Expand Down Expand Up @@ -71,7 +71,7 @@ private boolean isSourceOrTargetNotRegistered(String sourceFqn, String targetFqn
return this.lcomNodeRegistry.get(sourceFqn) == null || this.lcomNodeRegistry.get(targetFqn) == null;
}

public LCOMNode.Type resolveType(DiagramNode<PsiElement> referenceNode) {
private LCOMNode.Type resolveType(DiagramNode<PsiElement> referenceNode) {
PsiElementDispatcher<LCOMNode.Type> elementDispatcher = new PsiElementDispatcher<LCOMNode.Type>() {

@Override
Expand Down Expand Up @@ -130,4 +130,4 @@ public LCOMNode.Type processFile(PsiJavaFile psiElement) {
return elementDispatcher.dispatch(referenceNode.getIdentifyingElement());
}

}
}
2 changes: 1 addition & 1 deletion src/ch/docksnet/rgraph/PsiElementDispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
public abstract class PsiElementDispatcher<T> {

public T dispatch(PsiElement psiElement) {
T dispatch(PsiElement psiElement) {
if (psiElement instanceof PsiClass) {
if (((PsiClass) psiElement).getContainingClass() == null) {
return processClass((PsiClass) psiElement);
Expand Down
4 changes: 2 additions & 2 deletions src/ch/docksnet/rgraph/PsiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private static boolean classHasClassInitializer(PsiClass psiClass, PsiClassIniti
return false;
}

public static PsiClass getPsiClass(String classFQN, Project project) {
static PsiClass getPsiClass(String classFQN, Project project) {
return JavaPsiFacade.getInstance(project).findClass(classFQN, GlobalSearchScope
.projectScope(project));
}
Expand All @@ -147,7 +147,7 @@ private static String getName(PsiClassInitializer psiClassInitializer) {
}
}

public static String getPresentableName(PsiElement psiElement) {
static String getPresentableName(PsiElement psiElement) {
PsiElementDispatcher<String> psiElementDispatcher = new PsiElementDispatcher<String>() {

@Override
Expand Down
22 changes: 14 additions & 8 deletions src/ch/docksnet/rgraph/ReferenceDiagramDataModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@

import static ch.docksnet.rgraph.PsiUtils.getFqn;

@SuppressWarnings("MethodDoesntCallSuperMethod")
public abstract class ReferenceDiagramDataModel extends DiagramDataModel<PsiElement> {

private final Map<FQN, SmartPsiElementPointer<PsiElement>> elementsAddedByUser = new HashMap();
private final Map<FQN, SmartPsiElementPointer<PsiElement>> elementsRemovedByUser = new HashMap();
private final Map<FQN, SmartPsiElementPointer<PsiElement>> elementsAddedByUser = new HashMap<>();
private final Map<FQN, SmartPsiElementPointer<PsiElement>> elementsRemovedByUser = new HashMap<>();

private final Collection<DiagramNode<PsiElement>> nodes = new HashSet<>();
private final Map<PsiElement, DiagramNode<PsiElement>> nodesPool = new HashMap<>();
Expand Down Expand Up @@ -102,7 +103,7 @@ public void refreshDataModel() {
}


protected void refresh() {
private void refresh() {
analyzeLcom4();
updateToolWindow();
}
Expand All @@ -124,7 +125,7 @@ private Set<PsiElement> getElements() {
}

private void updateDataModel() {
DiagramProvider provider = getBuilder().getProvider();
DiagramProvider<?> provider = getBuilder().getProvider();
Set<PsiElement> elements = getElements();

for (PsiElement element : elements) {
Expand Down Expand Up @@ -201,7 +202,7 @@ protected SmartPsiElementPointer<PsiElement> createSmartPsiElementPointer(PsiEle
}

@NotNull
private ReferenceNode getReferenceNode(DiagramProvider provider, PsiElement element) {
private ReferenceNode getReferenceNode(DiagramProvider<?> provider, PsiElement element) {
if (this.nodesPool.containsKey(element)) {
return (ReferenceNode) this.nodesPool.get(element);
}
Expand All @@ -217,10 +218,10 @@ public boolean hasElement(PsiElement element) {

@Nullable
private DiagramNode<PsiElement> findNode(PsiElement psiElement) {
Iterator ptr = (new ArrayList(this.nodes)).iterator();
Iterator<?> ptr = (new ArrayList<>(this.nodes)).iterator();

while (ptr.hasNext()) {
DiagramNode node = (DiagramNode) ptr.next();
DiagramNode<PsiElement> node = (DiagramNode<PsiElement>) ptr.next();
FQN fqn = PsiUtils.getFqn((PsiElement) node.getIdentifyingElement());
if (fqn != null && fqn.equals(getFqn(psiElement))) {
return node;
Expand Down Expand Up @@ -288,7 +289,7 @@ private void analyzeLcom4() {
}

private void removeElement(PsiElement element) {
DiagramNode node = findNode(element);
DiagramNode<PsiElement> node = findNode(element);
if (node == null) {
this.elementsAddedByUser.remove(PsiUtils.getFqn(element));
} else {
Expand Down Expand Up @@ -359,6 +360,7 @@ public String getNodeName(DiagramNode<PsiElement> diagramNode) {
return PsiUtils.getPresentableName(diagramNode.getIdentifyingElement());
}

@SuppressWarnings("rawtypes")
public void markCallees(List<DiagramNode> roots) {
LCOMConverter lcomConverter = new LCOMConverter();
Collection<LCOMNode> lcom4Nodes = lcomConverter.convert(getNodes(), getEdges());
Expand All @@ -367,6 +369,7 @@ public void markCallees(List<DiagramNode> roots) {
}
}

@SuppressWarnings("rawtypes")
private void markCallees(DiagramNode root, Collection<LCOMNode> lcom4Nodes) {
LCOMNode lcomRoot = searchRoot(root, lcom4Nodes);
lcomRoot.getIdentifyingElement().setMarked();
Expand All @@ -376,6 +379,7 @@ private void markCallees(DiagramNode root, Collection<LCOMNode> lcom4Nodes) {
}
}

@SuppressWarnings("rawtypes")
private LCOMNode searchRoot(DiagramNode diagramNode, Collection<LCOMNode> lcom4Nodes) {
for (LCOMNode lcom4Node : lcom4Nodes) {
if (lcom4Node.getIdentifyingElement().equals(diagramNode)) {
Expand All @@ -392,6 +396,7 @@ private List<LCOMNode> getCalleesTransitiv(LCOMNode lcomRoot, Collection<LCOMNod
return result;
}

@SuppressWarnings("rawtypes")
public void markCallers(List<DiagramNode> roots) {
LCOMConverter lcomConverter = new LCOMConverter();
Collection<LCOMNode> lcom4Nodes = lcomConverter.convert(getNodes(), getEdges());
Expand All @@ -400,6 +405,7 @@ public void markCallers(List<DiagramNode> roots) {
}
}

@SuppressWarnings("rawtypes")
private void markCallers(DiagramNode root, Collection<LCOMNode> lcom4Nodes) {
LCOMNode lcomRoot = searchRoot(root, lcom4Nodes);
lcomRoot.getIdentifyingElement().setMarked();
Expand Down
1 change: 1 addition & 0 deletions src/ch/docksnet/rgraph/ReferenceDiagramElementManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
/**
* @author Stefan Zeller
*/
@SuppressWarnings("ALL")
public class ReferenceDiagramElementManager extends AbstractDiagramElementManager<PsiElement> {

/**
Expand Down
3 changes: 2 additions & 1 deletion src/ch/docksnet/rgraph/ReferenceDiagramExtras.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
/**
* @author Stefan Zeller
*/
@SuppressWarnings("MethodDoesntCallSuperMethod")
public class ReferenceDiagramExtras extends DiagramExtras<PsiElement> {

@Nullable
Expand Down Expand Up @@ -88,4 +89,4 @@ public JComponent createNodeComponent(DiagramNode<PsiElement> node, DiagramBuild
return nodeComponent;
}

}
}
1 change: 1 addition & 0 deletions src/ch/docksnet/rgraph/ReferenceDiagramProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
/**
* @author Stefan Zeller
*/
@SuppressWarnings("MethodDoesntCallSuperMethod")
public class ReferenceDiagramProvider extends BaseDiagramProvider<PsiElement> {

private static final String ID = "ReferenceDiagramProvider";
Expand Down
23 changes: 12 additions & 11 deletions src/ch/docksnet/rgraph/ReferenceUmlCategoryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@
/**
* @author Stefan Zeller
*/
@SuppressWarnings("MethodDoesntCallSuperMethod")
public class ReferenceUmlCategoryManager extends AbstractDiagramNodeContentManager {
public static final DiagramCategory STATIC_FIELDS;
public static final DiagramCategory FIELDS;
public static final DiagramCategory CONSTRUCTORS;
public static final DiagramCategory STATIC_METHODS;
public static final DiagramCategory METHODS;
public static final DiagramCategory STATIC_CLASS_INITIALIZER;
public static final DiagramCategory CLASS_INITIALIZER;
public static final DiagramCategory INNER_CLASS;
public static final DiagramCategory STATIC_INNER_CLASS;
public static final DiagramCategory ENUM;
private static final DiagramCategory STATIC_FIELDS;
private static final DiagramCategory FIELDS;
private static final DiagramCategory CONSTRUCTORS;
private static final DiagramCategory STATIC_METHODS;
private static final DiagramCategory METHODS;
private static final DiagramCategory STATIC_CLASS_INITIALIZER;
private static final DiagramCategory CLASS_INITIALIZER;
private static final DiagramCategory INNER_CLASS;
private static final DiagramCategory STATIC_INNER_CLASS;
private static final DiagramCategory ENUM;
private static final DiagramCategory[] CATEGORIES;

public ReferenceUmlCategoryManager() {
ReferenceUmlCategoryManager() {
}

public DiagramCategory[] getContentCategories() {
Expand Down
3 changes: 2 additions & 1 deletion src/ch/docksnet/rgraph/actions/MarkCalleesAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ public class MarkCalleesAction extends DiagramAction {

@Override
public void perform(AnActionEvent e) {
//noinspection rawtypes
List<DiagramNode> selectedNodes = getSelectedNodes(e);

DiagramDataModel dataModel = getDataModel(e);
DiagramDataModel<?> dataModel = getDataModel(e);
if (dataModel instanceof ReferenceDiagramDataModel) {
((ReferenceDiagramDataModel) dataModel).markCallees(selectedNodes);
}
Expand Down
1 change: 1 addition & 0 deletions src/ch/docksnet/rgraph/actions/MarkCallersAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
/**
* @author Stefan Zeller
*/
@SuppressWarnings("rawtypes")
public class MarkCallersAction extends DiagramAction {

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/ch/docksnet/rgraph/actions/ShowClusterCountAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

import ch.docksnet.rgraph.ReferenceDiagramDataModel;
import com.intellij.diagram.DiagramAction;
import com.intellij.diagram.DiagramBuilder;
import com.intellij.openapi.actionSystem.AnActionEvent;
import org.jetbrains.annotations.NotNull;

/**
* @author Stefan Zeller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ protected boolean isAllowedToShow(PsiElement psiElement) {
return true;
}
}
// fixme: remove this line. With IntelliJ 2021 getEnabledCategories() is not working properly any more. Always return true.
return true;
}
return false;
}
Expand Down

0 comments on commit 8710543

Please sign in to comment.