Commit 79495e5b authored by Michael Schwarz's avatar Michael Schwarz
Browse files

separate decls and precs in outline

parent 55fa1d48
...@@ -159,18 +159,19 @@ public class CupContentOutlinePage extends ContentOutlinePage implements ...@@ -159,18 +159,19 @@ public class CupContentOutlinePage extends ContentOutlinePage implements
// We currently will only expand if there is a small number of items. // We currently will only expand if there is a small number of items.
if (visitor.getProductionCount() < AUTO_EXPAND_L3_MAX_ITEMS if (visitor.getProductionCount() < AUTO_EXPAND_L3_MAX_ITEMS
&& visitor.getDeclPrecCount() < AUTO_EXPAND_L3_MAX_ITEMS) && visitor.getDeclAndPrecsCount() < AUTO_EXPAND_L3_MAX_ITEMS)
{ {
viewer.expandToLevel(3); viewer.expandToLevel(3);
} else if (visitor.getProductionCount() < AUTO_EXPAND_L2_MAX_ITEMS } else if (visitor.getProductionCount() < AUTO_EXPAND_L2_MAX_ITEMS
&& visitor.getDeclPrecCount() < AUTO_EXPAND_L2_MAX_ITEMS) && visitor.getDeclAndPrecsCount() < AUTO_EXPAND_L2_MAX_ITEMS)
{ {
viewer.expandToLevel(2); viewer.expandToLevel(2);
} }
// Even though we expanded before, we want to collapse decls and precs // Even though we expanded before, we want to collapse decls and precs
// and imports // and imports
viewer.setExpandedState(visitor.getDeclsAndPrec(), false); viewer.setExpandedState(visitor.getDecls(), false);
viewer.setExpandedState(visitor.getPrecs(), false);
viewer.setExpandedState(visitor.getImports(), false); viewer.setExpandedState(visitor.getImports(), false);
} }
finally { finally {
...@@ -250,10 +251,11 @@ public class CupContentOutlinePage extends ContentOutlinePage implements ...@@ -250,10 +251,11 @@ public class CupContentOutlinePage extends ContentOutlinePage implements
static public class OutlineVisitor extends Visitor<OutlineEntry> { static public class OutlineVisitor extends Visitor<OutlineEntry> {
private OutlineEntry root; private OutlineEntry root;
private int shortenListsTo; private int shortenListsTo;
private int declPrecCount; private int declAndPrecsCount;
private int productionCount; private int productionCount;
private OutlineEntry declsAndPrec; private OutlineEntry decls;
private OutlineEntry precs;
private OutlineEntry productions; private OutlineEntry productions;
private OutlineEntry imports; private OutlineEntry imports;
...@@ -261,8 +263,12 @@ public class CupContentOutlinePage extends ContentOutlinePage implements ...@@ -261,8 +263,12 @@ public class CupContentOutlinePage extends ContentOutlinePage implements
return root; return root;
} }
public OutlineEntry getDeclsAndPrec(){ public OutlineEntry getDecls(){
return declsAndPrec; return decls;
}
public OutlineEntry getPrecs(){
return precs;
} }
public OutlineEntry getImports(){ public OutlineEntry getImports(){
...@@ -273,8 +279,8 @@ public class CupContentOutlinePage extends ContentOutlinePage implements ...@@ -273,8 +279,8 @@ public class CupContentOutlinePage extends ContentOutlinePage implements
return productionCount; return productionCount;
} }
public int getDeclPrecCount() { public int getDeclAndPrecsCount() {
return declPrecCount; return declAndPrecsCount;
} }
public OutlineVisitor() { public OutlineVisitor() {
...@@ -282,14 +288,24 @@ public class CupContentOutlinePage extends ContentOutlinePage implements ...@@ -282,14 +288,24 @@ public class CupContentOutlinePage extends ContentOutlinePage implements
this.shortenListsTo = 3; this.shortenListsTo = 3;
} }
private void addDeclOrPrec(OutlineEntry entry) { private void addDecl(OutlineEntry entry) {
if (declsAndPrec == null) { if (decls == null) {
this.declsAndPrec = OutlineEntry this.decls = OutlineEntry
.folderFromNode("Declarations and Precedences"); .folderFromNode("Declarations");
root.children.add(declsAndPrec); root.children.add(decls);
}
decls.children.add(entry);
declAndPrecsCount++;
}
private void addPrec(OutlineEntry entry) {
if (precs == null) {
this.precs = OutlineEntry
.folderFromNode("Precedences");
root.children.add(precs);
} }
declsAndPrec.children.add(entry); precs.children.add(entry);
declPrecCount++; declAndPrecsCount++;
} }
private void addImport(OutlineEntry entry) { private void addImport(OutlineEntry entry) {
...@@ -359,7 +375,7 @@ public class CupContentOutlinePage extends ContentOutlinePage implements ...@@ -359,7 +375,7 @@ public class CupContentOutlinePage extends ContentOutlinePage implements
builder.append(Utility.shortenedList(node.getTerminals(), builder.append(Utility.shortenedList(node.getTerminals(),
t -> t.getNameStringOrNull(), this.shortenListsTo)); t -> t.getNameStringOrNull(), this.shortenListsTo));
} }
addDeclOrPrec(OutlineEntry.fromNode(builder.toString(), node)); addPrec(OutlineEntry.fromNode(builder.toString(), node));
} }
@Override @Override
...@@ -419,27 +435,27 @@ public class CupContentOutlinePage extends ContentOutlinePage implements ...@@ -419,27 +435,27 @@ public class CupContentOutlinePage extends ContentOutlinePage implements
@Override @Override
public void postVisit(NonTerminalDeclaration node, OutlineEntry data) { public void postVisit(NonTerminalDeclaration node, OutlineEntry data) {
addDeclOrPrec(OutlineEntry.fromNode( addDecl(OutlineEntry.fromNode(
shortenNonTerminals(node.getNonTerminals()), node)); shortenNonTerminals(node.getNonTerminals()), node));
} }
@Override @Override
public void postVisit(TerminalDeclaration node, OutlineEntry data) { public void postVisit(TerminalDeclaration node, OutlineEntry data) {
addDeclOrPrec(OutlineEntry.fromNode( addDecl(OutlineEntry.fromNode(
shortenTerminals(node.getTerminals()), node)); shortenTerminals(node.getTerminals()), node));
} }
@Override @Override
public void postVisit(TypedNonTerminalDeclaration node, public void postVisit(TypedNonTerminalDeclaration node,
OutlineEntry data) { OutlineEntry data) {
addDeclOrPrec(OutlineEntry.fromNode( addDecl(OutlineEntry.fromNode(
shortenNonTerminals(node.getNonTerminals()), node.type, shortenNonTerminals(node.getNonTerminals()), node.type,
node)); node));
} }
@Override @Override
public void postVisit(TypedTerminalDeclaration node, OutlineEntry data) { public void postVisit(TypedTerminalDeclaration node, OutlineEntry data) {
addDeclOrPrec(OutlineEntry.fromNode( addDecl(OutlineEntry.fromNode(
shortenTerminals(node.getTerminals()), node.type, node)); shortenTerminals(node.getTerminals()), node.type, node));
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment