|
7 | 7 | import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; |
8 | 8 |
|
9 | 9 | import java.io.IOException; |
| 10 | +import java.lang.reflect.InvocationTargetException; |
| 11 | +import java.lang.reflect.Method; |
10 | 12 | import java.util.Arrays; |
11 | 13 | import java.util.Collections; |
12 | | -import java.util.List; |
13 | | -import java.util.Vector; |
14 | | -import java.util.Hashtable; |
15 | 14 | import java.util.HashSet; |
| 15 | +import java.util.Hashtable; |
| 16 | +import java.util.List; |
16 | 17 | import java.util.Stack; |
17 | | -import java.lang.Comparable; |
18 | | -import java.lang.reflect.Method; |
19 | | -import java.lang.reflect.InvocationTargetException; |
| 18 | +import java.util.Vector; |
20 | 19 |
|
21 | 20 | /// Visitor pattern implementation for the CPP AST. This will write every |
22 | 21 | /// node in the Json output. Since CDT unfortunately doesnt have something like JDT |
|
25 | 24 | /// children that derive for IASTNode (including all the ones returned by any method |
26 | 25 | /// of that node returning an IASTNode-derived object), a lot of nodes also have |
27 | 26 | /// other methods that return something not derived from IASTNode and thus not returned |
28 | | -/// by getChildren. So for all these IASTNode subinterfaces we must call and store the |
| 27 | +/// by getChildren. So for all these IASTNode sub-interfaces we must call and store the |
29 | 28 | /// value of those non-IASTNode-returning methods. The most infamous is probably the |
30 | 29 | /// getOperator of some nodes that return an int than then you have to match in a switch |
31 | | -/// because the possible values are not even declarated in an enum but as final int |
| 30 | +/// because the possible values are not even declared in an enum but as final int |
32 | 31 | /// class members. |
33 | 32 |
|
34 | 33 | public class JsonASTVisitor extends ASTVisitor { |
@@ -1293,12 +1292,16 @@ private void serializePreproStatements(IASTTranslationUnit unit) throws IOExcept |
1293 | 1292 | IASTPreprocessorIfndefStatement s = (IASTPreprocessorIfndefStatement)stmt; |
1294 | 1293 | json.writeStringField("Condition", new String(s.getCondition())); |
1295 | 1294 | json.writeBooleanField("IsTaken", s.taken()); |
1296 | | - json.writeStringField("MacroReference", s.getMacroReference().toString()); |
| 1295 | + if (s.getMacroReference() != null ) { |
| 1296 | + json.writeStringField("MacroReference", s.getMacroReference().toString()); |
| 1297 | + } |
1297 | 1298 | } else if (stmt instanceof IASTPreprocessorIfdefStatement) { |
1298 | 1299 | IASTPreprocessorIfdefStatement s = (IASTPreprocessorIfdefStatement)stmt; |
1299 | 1300 | json.writeStringField("Condition", new String(s.getCondition())); |
1300 | 1301 | json.writeBooleanField("IsTaken", s.taken()); |
1301 | | - json.writeStringField("MacroReference", s.getMacroReference().toString()); |
| 1302 | + if (s.getMacroReference() != null ) { |
| 1303 | + json.writeStringField("MacroReference", s.getMacroReference().toString()); |
| 1304 | + } |
1302 | 1305 | } else if (stmt instanceof IASTPreprocessorElifStatement) { |
1303 | 1306 | IASTPreprocessorElifStatement s = (IASTPreprocessorElifStatement)stmt; |
1304 | 1307 | json.writeStringField("Condition", new String(s.getCondition())); |
|
0 commit comments