|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.testfw.codegen.ui.parser; |
|
19 |
|
20 import java.util.Collection; |
|
21 |
|
22 import org.eclipse.cdt.core.model.ICElement; |
|
23 import org.eclipse.cdt.core.model.ICElementVisitor; |
|
24 import org.eclipse.cdt.core.model.ITranslationUnit; |
|
25 import org.eclipse.core.runtime.CoreException; |
|
26 import org.eclipse.core.runtime.IProgressMonitor; |
|
27 |
|
28 final public class TranslationUnitCollector implements ICElementVisitor { |
|
29 private final Collection<ITranslationUnit> fSources; |
|
30 private final Collection<ITranslationUnit> fHeaders; |
|
31 private final IProgressMonitor fProgressMonitor; |
|
32 |
|
33 public TranslationUnitCollector(Collection<ITranslationUnit> sources, |
|
34 Collection<ITranslationUnit> headers, IProgressMonitor pm) { |
|
35 fSources = sources; |
|
36 fHeaders = headers; |
|
37 fProgressMonitor = pm; |
|
38 } |
|
39 |
|
40 public boolean visit(ICElement element) throws CoreException { |
|
41 if (fProgressMonitor.isCanceled()) { |
|
42 return false; |
|
43 } |
|
44 switch (element.getElementType()) { |
|
45 case ICElement.C_UNIT: |
|
46 ITranslationUnit tu = (ITranslationUnit) element; |
|
47 if (fSources != null && tu.isSourceUnit()) { |
|
48 fSources.add(tu); |
|
49 } else if (fHeaders != null && tu.isHeaderUnit()) { |
|
50 fHeaders.add(tu); |
|
51 } |
|
52 return false; |
|
53 case ICElement.C_CCONTAINER: |
|
54 case ICElement.C_PROJECT: |
|
55 return true; |
|
56 } |
|
57 return false; |
|
58 } |
|
59 } |