Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b886ad336e00a39bb5ef1a61f7325d7fd2244150 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*******************************************************************************
 * Copyright (c) 2011, 2014 Red Hat Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Red Hat Inc. - initial API and implementation
 *     Red Hat Inc. - add support for specifying multiple flag names at once
 *******************************************************************************/
package org.eclipse.cdt.internal.autotools.core.configure;

import java.util.ArrayList;

public class FlagConfigureOption extends AbstractConfigurationOption {

	private String value;
	private ArrayList<String> children = 
			new ArrayList<String>();
	
	public FlagConfigureOption(String name, AutotoolsConfiguration cfg) {
		super(name, cfg);
		this.value = ""; // $NON-NLS-1$
	}
	
	public FlagConfigureOption(String name, String msgName, AutotoolsConfiguration cfg) {
		super(name, msgName, cfg);
		this.value = ""; // $NON-NLS-1$
	}
	
	@SuppressWarnings("unchecked")
	private FlagConfigureOption(String name, AutotoolsConfiguration cfg,
			String value, ArrayList<String> children) {
		super(name, cfg);
		this.value = value;
		this.children = (ArrayList<String>)children.clone();
	}
	
	public String getParameter() {
		StringBuffer parms = new StringBuffer();
		// Multiple flags are designated by putting multiple flags together using "|" as delimiter
		String[] flagNames = getName().split("\\|"); //$NON-NLS-1$
		String flagSeparator = "";
		for (String flagName : flagNames) {
			parms.append(flagSeparator);
			flagSeparator = " "; //$NON-NLS-1$
			StringBuffer parm = new StringBuffer(flagName+"=\""); //$NON-NLS-1$
			boolean haveParm = false;
			if (isParmSet()) {
				String separator = "";
				for (int i = 0; i < children.size(); ++i) {
					String fvname = children.get(i);
					IConfigureOption o = cfg.getOption(fvname);
					if (o.isParmSet()) {
						if (o instanceof IFlagConfigureValueOption) {
							parm.append(separator + ((IFlagConfigureValueOption)o).getFlags()); //$NON-NLS-1$
							separator = " ";
							haveParm = true;
						}
					}
				}
				if (haveParm) {
					parm.append("\""); //$NON-NLS-1$
					parms.append(parm);
				}
			}
		}
		return parms.toString();
	}

	public String getParameterName() {
		return getName();
	}
	
	public boolean isParmSet() {
		for (int i = 0; i < children.size(); ++i) {
			String s = children.get(i);
			IConfigureOption o = cfg.getOption(s);
			if (o.isParmSet())
				return true;
		}
		return false;
	}

	public void setValue(String value) {
		// can't occur
	}

	public IConfigureOption copy(AutotoolsConfiguration config) {
		FlagConfigureOption f = new FlagConfigureOption(name, config, value, children);
		return f; 
	}

	public String getValue() {
		return value;
	}

	public int getType() {
		return FLAG;
	}
	
	public boolean isFlag() {
		return true;
	}
	
	public void addChild(String name) {
		children.add(name);
	}
	
	public ArrayList<String> getChildren() {
		return children;
	}
	
}

Back to the top