blob: bc2a9b3942d7d06fc949e11715d2c755db210379 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/*******************************************************************************
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite;
import java.util.HashMap;
/**
* Collects modifications to an AST in a hierarchical manner. The store gives access to
* the root modifications and for each modification you can obtain the nested modifications here.
* @since 5.0
*/
public class ASTModificationStore {
private HashMap<ASTModification,ASTModificationMap> fNestedModMaps;
public ASTModificationStore() {
fNestedModMaps= new HashMap<ASTModification, ASTModificationMap>();
}
/**
* Adds a potentially nested modification to the store.
* @param parentMod the parent for a nested modification, or <code>null</code>
* @param mod a modification
*/
public void storeModification(ASTModification parentMod, ASTModification mod) {
ASTModificationMap modMap = createNestedModificationMap(parentMod);
modMap.addModification(mod);
}
private ASTModificationMap createNestedModificationMap(ASTModification parentMod) {
ASTModificationMap modMap= fNestedModMaps.get(parentMod);
if (modMap == null) {
modMap= new ASTModificationMap();
fNestedModMaps.put(parentMod, modMap);
}
return modMap;
}
/**
* Returns the modifications that are performed directly on the AST, or <code>null</code> if there
* are no modifications.
* @return the root modifications or <code>null</code>.
*/
public ASTModificationMap getRootModifications() {
return fNestedModMaps.get(null);
}
/**
* Returns the modifications that are performed on the node that has been introduced by the
* given modification. If there are no nested modifications, <code>null</code> is returned.
* @return the nested modifications or <code>null</code>.
*/
public ASTModificationMap getNestedModifications(ASTModification mod) {
return fNestedModMaps.get(mod);
}
}
|