Skip to content

Commit

Permalink
feat: add simple support for enter/exit in DJPP as in CtScanner (#1538)
Browse files Browse the repository at this point in the history
  • Loading branch information
monperrus authored and pvojtechovsky committed Sep 19, 2017
1 parent 0caf179 commit 494ba6f
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/main/java/spoon/reflect/visitor/DefaultJavaPrettyPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,28 @@ public void computeImports(CtElement element) {
}
}

/**
* This method is called by {@link #scan(CtElement)} when entering a scanned element.
* To be overridden to implement specific behavior.
*
* Same KISS design as for {@link CtScanner}.
*/
protected void enter(CtElement e) {
}

/**
* This method is called by {@link #scan(CtElement)} when entering a scanned element.
* To be overridden to implement specific behavior.
*/
protected void exit(CtElement e) {
}

/**
* The generic scan method for an element.
*/
public DefaultJavaPrettyPrinter scan(CtElement e) {
if (e != null) {
enter(e);
context.elementStack.push(e);
if (env.isPreserveLineNumbers()) {
if (!(e instanceof CtNamedElement)) {
Expand All @@ -317,6 +334,7 @@ public DefaultJavaPrettyPrinter scan(CtElement e) {
throw new SpoonException("Printing of " + elementInfo + "failed", ex);
}
context.elementStack.pop();
exit(e);
}
return this;
}
Expand Down Expand Up @@ -344,16 +362,6 @@ private static void addParentPath(StringBuilder sb, CtElement ele) {
}
}

/**
* The generic scan method for a reference.
*/
public DefaultJavaPrettyPrinter scan(CtReference ref) {
if (ref != null) {
ref.accept(this);
}
return this;
}

private boolean shouldSetBracket(CtExpression<?> e) {
if (e.getTypeCasts().size() != 0) {
return true;
Expand Down

0 comments on commit 494ba6f

Please sign in to comment.