1 | /******************************************************************************* |
---|---|
2 | * Copyright (c) 2000, 2013 IBM Corporation and others. |
3 | * |
4 | * This program and the accompanying materials |
5 | * are made available under the terms of the Eclipse Public License 2.0 |
6 | * which accompanies this distribution, and is available at |
7 | * https://www.eclipse.org/legal/epl-2.0/ |
8 | * |
9 | * SPDX-License-Identifier: EPL-2.0 |
10 | * |
11 | * Contributors: |
12 | * IBM Corporation - initial API and implementation |
13 | *******************************************************************************/ |
14 | package org.eclipse.jdt.astview; |
15 | |
16 | import org.eclipse.jdt.core.dom.ASTNode; |
17 | import org.eclipse.jdt.core.dom.ASTVisitor; |
18 | import org.eclipse.jdt.core.dom.CompilationUnit; |
19 | |
20 | /** |
21 | * |
22 | */ |
23 | public class TreeInfoCollector { |
24 | |
25 | public static class NodeCounter extends ASTVisitor { |
26 | |
27 | public int numberOfNodes= 0; |
28 | |
29 | @Override |
30 | public void preVisit(ASTNode node) { |
31 | numberOfNodes++; |
32 | } |
33 | } |
34 | |
35 | |
36 | private final CompilationUnit fRoot; |
37 | |
38 | public TreeInfoCollector(CompilationUnit root) { |
39 | fRoot= root; |
40 | } |
41 | |
42 | public int getSize() { |
43 | return fRoot.subtreeBytes(); |
44 | } |
45 | |
46 | public int getNumberOfNodes() { |
47 | NodeCounter counter= new NodeCounter(); |
48 | fRoot.accept(counter); |
49 | return counter.numberOfNodes; |
50 | } |
51 | |
52 | |
53 | } |
54 |
Members