Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: bb1060767396a51932c55226ae10a32b12ce7410 (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
/*******************************************************************************
 * Copyright (c) 2007, 2016 Intel Corporation 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:
 *    Intel Corporation - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.core.settings.model;

import org.eclipse.cdt.core.settings.model.util.CDataUtil;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;

/**
 * Representation in the project model of library file settings entries.
 * As an example, those are supplied by a gcc compiler with option "-l".
 */
public final class CLibraryFileEntry extends ACPathEntry implements ICLibraryFileEntry {
	private final IPath fSourceAttachmentPath;
	private final IPath fSourceAttachmentRootPath;
	private final IPath fSourceAttachmentPrefixMapping;

	/**
	 * This constructor is discouraged to be referenced by clients.
	 *
	 * Instead, use pooled entries with CDataUtil.createCLibraryFileEntry(name, flags).
	 *
	 * @param name - library file path. The path can be an absolute location on the local file-system
	 *    or with flag {@link #VALUE_WORKSPACE_PATH} it is treated as workspace full path.
	 * @param flags - bitwise combination of {@link ICSettingEntry} flags.
	 */
	public CLibraryFileEntry(String name, int flags) {
		this(name, flags, null, null, null);
	}

	/**
	 * This constructor is discouraged to be used directly.
	 *
	 * Instead, use pooled entries with CDataUtil.createCLibraryFileEntry(location.toString(), flags)
	 * or wrap it with CDataUtil.getPooledEntry(new CLibraryFileEntry(location, flags)).
	 *
	 * @param location - library file path. The path can be an absolute location on the local
	 *    file-system or with flag {@link #VALUE_WORKSPACE_PATH} it is treated as workspace full path.
	 * @param flags - bitwise combination of {@link ICSettingEntry} flags.
	 */
	public CLibraryFileEntry(IPath location, int flags) {
		this(location, flags, null, null, null);
	}

	/**
	 * This constructor is discouraged to be used directly.
	 *
	 * Instead, use pooled entries wrapping with CDataUtil.getPooledEntry(new CLibraryFileEntry(rc, flags)).
	 *
	 * @param rc - library file as a resource in the workspace.
	 * @param flags - bitwise combination of {@link ICSettingEntry} flags.
	 *    If {@link #VALUE_WORKSPACE_PATH} is missing it will be supplied.
	 */
	public CLibraryFileEntry(IFile rc, int flags) {
		this(rc, flags, null, null, null);
	}

	public CLibraryFileEntry(String name, int flags,
			IPath sourceAttachmentPath,
			IPath sourceAttachmentRootPath,
			IPath sourceAttachmentPrefixMapping) {
		super(name, flags);

		fSourceAttachmentPath = sourceAttachmentPath;
		fSourceAttachmentRootPath = sourceAttachmentRootPath != null ? sourceAttachmentRootPath : Path.EMPTY;
		fSourceAttachmentPrefixMapping = sourceAttachmentPrefixMapping != null ? sourceAttachmentPrefixMapping : Path.EMPTY;
	}

	public CLibraryFileEntry(IPath location, int flags,
			IPath sourceAttachmentPath,
			IPath sourceAttachmentRootPath,
			IPath sourceAttachmentPrefixMapping) {
		super(location, flags);

		fSourceAttachmentPath = sourceAttachmentPath;
		fSourceAttachmentRootPath = sourceAttachmentRootPath != null ? sourceAttachmentRootPath : Path.EMPTY;
		fSourceAttachmentPrefixMapping = sourceAttachmentPrefixMapping != null ? sourceAttachmentPrefixMapping : Path.EMPTY;
	}

	public CLibraryFileEntry(IFile rc, int flags,
			IPath sourceAttachmentPath,
			IPath sourceAttachmentRootPath,
			IPath sourceAttachmentPrefixMapping) {
		super(rc, flags);

		fSourceAttachmentPath = sourceAttachmentPath;
		fSourceAttachmentRootPath = sourceAttachmentRootPath != null ? sourceAttachmentRootPath : Path.EMPTY;
		fSourceAttachmentPrefixMapping = sourceAttachmentPrefixMapping != null ? sourceAttachmentPrefixMapping : Path.EMPTY;
	}

	@Override
	public final int getKind() {
		return LIBRARY_FILE;
	}

	@Override
	public final boolean isFile() {
		return true;
	}

	@Override
	public IPath getSourceAttachmentPath() {
		return fSourceAttachmentPath;
	}

	@Override
	public IPath getSourceAttachmentPrefixMapping() {
		return fSourceAttachmentPrefixMapping;
	}

	@Override
	public IPath getSourceAttachmentRootPath() {
		return fSourceAttachmentRootPath;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((fSourceAttachmentPath == null) ? 0 : fSourceAttachmentPath.hashCode());
		result = prime * result + ((fSourceAttachmentPrefixMapping == null) ? 0 : fSourceAttachmentPrefixMapping.hashCode());
		result = prime * result + ((fSourceAttachmentRootPath == null) ? 0 : fSourceAttachmentRootPath.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object other) {
		if(other == this)
			return true;

		if(!super.equals(other))
			return false;

		return sourceAttachmentSettingsEqual((CLibraryFileEntry)other);
	}

	@Override
	public boolean equalsByContents(ICSettingEntry entry) {
		if(entry == this)
			return true;

		if(!super.equalsByContents(entry))
			return false;

		return sourceAttachmentSettingsEqual((CLibraryFileEntry)entry);
	}

	private boolean sourceAttachmentSettingsEqual(CLibraryFileEntry otherEntry){
		if(!CDataUtil.objectsEqual(fSourceAttachmentPath, otherEntry.fSourceAttachmentPath))
			return false;
		if(!CDataUtil.objectsEqual(fSourceAttachmentRootPath, otherEntry.fSourceAttachmentRootPath))
			return false;
		if(!CDataUtil.objectsEqual(fSourceAttachmentPrefixMapping, otherEntry.fSourceAttachmentPrefixMapping))
			return false;
		return true;
	}

	@Override
	protected String contentsToString() {
		String result = super.contentsToString();

		if(fSourceAttachmentPath != null){
			StringBuilder buf = new StringBuilder();
			buf.append(result);
			buf.append(" ; srcPath=").append(fSourceAttachmentPath); //$NON-NLS-1$
			buf.append("; srcRoot=").append(fSourceAttachmentRootPath); //$NON-NLS-1$
			buf.append("; srcMapping=").append(fSourceAttachmentPrefixMapping); //$NON-NLS-1$

			result = buf.toString();
		}
		return result;
	}
}

Back to the top