1 | /* |
---|---|
2 | * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. |
3 | * Copyright (C) 2011, 2013-2020 The JavaParser Team. |
4 | * |
5 | * This file is part of JavaParser. |
6 | * |
7 | * JavaParser can be used either under the terms of |
8 | * a) the GNU Lesser General Public License as published by |
9 | * the Free Software Foundation, either version 3 of the License, or |
10 | * (at your option) any later version. |
11 | * b) the terms of the Apache License |
12 | * |
13 | * You should have received a copy of both licenses in LICENCE.LGPL and |
14 | * LICENCE.APACHE. Please refer to those files for details. |
15 | * |
16 | * JavaParser is distributed in the hope that it will be useful, |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 | * GNU Lesser General Public License for more details. |
20 | */ |
21 | |
22 | package com.github.javaparser.version; |
23 | |
24 | import com.github.javaparser.ParseResult; |
25 | import com.github.javaparser.ParserConfiguration; |
26 | import com.github.javaparser.ast.Node; |
27 | |
28 | import java.util.ArrayList; |
29 | import java.util.Arrays; |
30 | import java.util.List; |
31 | |
32 | import static com.github.javaparser.ParseResult.PostProcessor; |
33 | |
34 | /** |
35 | * A post processor that will call a collection of post processors. |
36 | */ |
37 | public class PostProcessors implements PostProcessor { |
38 | private final List<PostProcessor> postProcessors = new ArrayList<>(); |
39 | |
40 | public PostProcessors(PostProcessor... postProcessors) { |
41 | this.postProcessors.addAll(Arrays.asList(postProcessors)); |
42 | } |
43 | |
44 | public List<PostProcessor> getPostProcessors() { |
45 | return postProcessors; |
46 | } |
47 | |
48 | public PostProcessors remove(PostProcessor postProcessor) { |
49 | if (!postProcessors.remove(postProcessor)) { |
50 | throw new AssertionError("Trying to remove a post processor that isn't there."); |
51 | } |
52 | return this; |
53 | } |
54 | |
55 | public PostProcessors replace(PostProcessor oldProcessor, PostProcessor newProcessor) { |
56 | remove(oldProcessor); |
57 | add(newProcessor); |
58 | return this; |
59 | } |
60 | |
61 | public PostProcessors add(PostProcessor newProcessor) { |
62 | postProcessors.add(newProcessor); |
63 | return this; |
64 | } |
65 | |
66 | @Override |
67 | public void process(ParseResult<? extends Node> result, ParserConfiguration configuration) { |
68 | postProcessors.forEach(pp -> pp.process(result, configuration)); |
69 | } |
70 | } |
71 |
Members