Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 83a62ec83692abf44478af6fac2f94ca491cf27b (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*******************************************************************************
 * Copyright (c) 2007, 2016 Intel Corporation and others.
 * 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:
 * Intel Corporation - Initial API and implementation
 * IBM Corporation
 *******************************************************************************/
package org.eclipse.cdt.managedbuilder.core;

import org.eclipse.cdt.core.settings.model.ICLibraryFileEntry;
import org.eclipse.cdt.core.settings.model.ICStorageElement;
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
import org.eclipse.cdt.internal.core.SafeStringInterner;
import org.eclipse.cdt.managedbuilder.internal.core.Option;

public final class OptionStringValue {
	private static final String ATTR_SRC_PATH = "srcPath";  //$NON-NLS-1$
	private static final String ATTR_SRC_ROOT_PATH = "srcRootPath"; //$NON-NLS-1$
	private static final String ATTR_SRC_PREFIX_MAPPING = "srcPrefixMapping"; //$NON-NLS-1$

	private String value;
	private String srcPath;
	private String srcRootPath;
	private String srcPrefixMapping;
	private boolean isBuiltIn;
	
	public OptionStringValue(ICStorageElement el){
		if (el.getAttribute(Option.LIST_ITEM_BUILTIN) != null) {
			isBuiltIn = Boolean.valueOf(el.getAttribute(Option.LIST_ITEM_BUILTIN)).booleanValue();
		} else {
			isBuiltIn = false;
		}
		value = el.getAttribute(Option.LIST_ITEM_VALUE);
		srcPath = el.getAttribute(ATTR_SRC_PATH);
		srcRootPath = el.getAttribute(ATTR_SRC_ROOT_PATH);
		srcPrefixMapping = el.getAttribute(ATTR_SRC_PREFIX_MAPPING);
		if(value == null)
			value = Option.EMPTY_STRING;
	}

	public OptionStringValue(IManagedConfigElement el){
		if (el.getAttribute(Option.LIST_ITEM_BUILTIN) != null) {
			isBuiltIn = Boolean.valueOf(el.getAttribute(Option.LIST_ITEM_BUILTIN)).booleanValue();
		} else {
			isBuiltIn = false;
		}
		value = SafeStringInterner.safeIntern(el.getAttribute(Option.LIST_ITEM_VALUE));
		srcPath = SafeStringInterner.safeIntern(el.getAttribute(ATTR_SRC_PATH));
		srcRootPath = SafeStringInterner.safeIntern(el.getAttribute(ATTR_SRC_ROOT_PATH));
		srcPrefixMapping = SafeStringInterner.safeIntern(el.getAttribute(ATTR_SRC_PREFIX_MAPPING));
		if(value == null)
			value = Option.EMPTY_STRING;
	}

	public OptionStringValue(OptionStringValue base){
		isBuiltIn = base.isBuiltIn;
		value = base.value;
		srcPath = base.srcPath;
		srcRootPath = base.srcRootPath;
		srcPrefixMapping = base.srcPrefixMapping;
	}

	public OptionStringValue(String value){
		this(value, false);
	}

	public OptionStringValue(String value, boolean isBuiltIn){
		this(value, isBuiltIn, null, null, null);
	}

	/**
	 * source path settings are applicable for the {@link IOption#LIBRARY_FILES} only
	 */
	public OptionStringValue(String value, boolean isBuiltIn, String srcPath, String srcRootPath, String srcPrefixMapping){
		if(value == null)
			value = Option.EMPTY_STRING;
		this.isBuiltIn = isBuiltIn;
		this.value = value;
		this.srcPath = srcPath;
		this.srcRootPath = srcRootPath;
		this.srcPrefixMapping = srcPrefixMapping;
	}
	
	public void serialize(ICStorageElement el){
		el.setAttribute(Option.LIST_ITEM_VALUE, value);
		el.setAttribute(Option.LIST_ITEM_BUILTIN, Boolean.toString(isBuiltIn));
		if(srcPath != null)
			el.setAttribute(ATTR_SRC_PATH, srcPath);
		if(srcRootPath != null)
			el.setAttribute(ATTR_SRC_ROOT_PATH, srcRootPath);
		if(srcPrefixMapping != null)
			el.setAttribute(ATTR_SRC_PREFIX_MAPPING, srcPrefixMapping);
	}

	public boolean isBuiltIn(){
		return isBuiltIn;
	}
	
	public String getValue(){
		return value;
	}

	/**
	 * source attachment settings are applicable for the {@link IOption#LIBRARY_FILES} only
	 * added to fully support the {@link ICLibraryFileEntry} settings 
	 * 
	 * @see ICLibraryFileEntry
	 * @see ICLibraryFileEntry#getSourceAttachmentPath()
	 * @see ICLibraryFileEntry#getSourceAttachmentRootPath()
	 * @see ICLibraryFileEntry#getSourceAttachmentPrefixMapping()
	 * 
	 */
	public String getSourceAttachmentPath(){
		return srcPath;
	}

	/**
	 * source attachment settings are applicable for the {@link IOption#LIBRARY_FILES} only
	 * added to fully support the {@link ICLibraryFileEntry} settings 
	 * 
	 * @see ICLibraryFileEntry
	 * @see ICLibraryFileEntry#getSourceAttachmentPath()
	 * @see ICLibraryFileEntry#getSourceAttachmentRootPath()
	 * @see ICLibraryFileEntry#getSourceAttachmentPrefixMapping()
	 * 
	 */
	public String getSourceAttachmentRootPath(){
		return srcRootPath;
	}

	/**
	 * source attachment settings are applicable for the {@link IOption#LIBRARY_FILES} only
	 * added to fully support the {@link ICLibraryFileEntry} settings 
	 * 
	 * @see ICLibraryFileEntry
	 * @see ICLibraryFileEntry#getSourceAttachmentPath()
	 * @see ICLibraryFileEntry#getSourceAttachmentRootPath()
	 * @see ICLibraryFileEntry#getSourceAttachmentPrefixMapping()
	 * 
	 */
	public String getSourceAttachmentPrefixMapping(){
		return srcPrefixMapping;
	}

	@Override
	public boolean equals(Object obj) {
		if(obj == this)
			return true;
		
		if(!(obj instanceof OptionStringValue))
			return false;
		
		OptionStringValue other = (OptionStringValue)obj;
		
		if(isBuiltIn != other.isBuiltIn)
			return false;
		
		if(!CDataUtil.objectsEqual(value, other.value))
			return false;

		if(!CDataUtil.objectsEqual(srcPath, other.srcPath))
			return false;

		if(!CDataUtil.objectsEqual(srcRootPath, other.srcRootPath))
			return false;

		if(!CDataUtil.objectsEqual(srcPrefixMapping, other.srcPrefixMapping))
			return false;

		return true;
	}

	@Override
	public int hashCode() {
		return code(value);
	}
	
	private static int code(String str){
		return str != null ? str.hashCode() : 0;
	}

	@Override
	public String toString() {
		return new StringBuilder().append("ov:").append(value.toString()).toString(); //$NON-NLS-1$
	}
}

Back to the top