Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0fd02f1d1758e27b5190eee704e003a1d15b64a4 (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
/*******************************************************************************
 * Copyright (c) 2007, 2011 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 java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.eclipse.cdt.core.settings.model.util.CEntriesSet;
import org.eclipse.cdt.core.settings.model.util.KindBasedStore;

public final class CExternalSetting implements ICExternalSetting {
	//	private EntryStore fEntryStore = new EntryStore();
	private KindBasedStore<CEntriesSet> fStore = new KindBasedStore<CEntriesSet>(false);
	private String[] fContentTypeIds;
	private String[] fLanguageIds;
	private String[] fExtensions;
	//	private String fId;

	public CExternalSetting(ICExternalSetting base) {
		fLanguageIds = base.getCompatibleLanguageIds();
		fContentTypeIds = base.getCompatibleContentTypeIds();
		fExtensions = base.getCompatibleExtensions();

		//		fEntryStore = new EntryStore();
		initEntryStore(base.getEntries());
	}

	public CExternalSetting(ICExternalSetting base, ICSettingEntry entries[]) {
		this(base);

		initEntryStore(entries);
	}

	public CExternalSetting(String[] languageIDs, String[] contentTypeIds, String[] extensions,
			ICSettingEntry[] entries) {
		if (languageIDs != null)
			fLanguageIds = languageIDs.clone();
		if (contentTypeIds != null)
			fContentTypeIds = contentTypeIds.clone();
		if (extensions != null)
			fExtensions = extensions.clone();

		initEntryStore(entries);
	}

	private void initEntryStore(ICSettingEntry entries[]) {
		ICSettingEntry entry;
		for (int i = 0; i < entries.length; i++) {
			entry = entries[i];

			addEntry(entry);
		}

		//		trimToSize();
	}

	private void addEntry(ICSettingEntry entry) {
		getEntriesSet(entry.getKind(), true).addEntry(entry);
	}

	//	private void trimToSize() {
	//		int kinds[] = KindBasedStore.getSupportedKinds();
	//		for (int i = 0; i < kinds.length; i++) {
	//			CEntriesSet set = getEntriesSet(kinds[i], false);
	//			if (set != null)
	//				set.trimToSize();
	//		}
	//	}

	private CEntriesSet getEntriesSet(int kind, boolean create) {
		CEntriesSet set = fStore.get(kind);
		if (set == null && create) {
			set = new CEntriesSet();
			fStore.put(kind, set);
		}
		return set;
	}

	@Override
	public String[] getCompatibleContentTypeIds() {
		if (fContentTypeIds != null)
			return fContentTypeIds.clone();
		return null;
	}

	@Override
	public String[] getCompatibleExtensions() {
		if (fExtensions != null)
			return fExtensions.clone();
		return null;
	}

	@Override
	public String[] getCompatibleLanguageIds() {
		if (fLanguageIds != null)
			return fLanguageIds.clone();
		return null;
	}

	@Override
	public ICSettingEntry[] getEntries(int kind) {
		CEntriesSet set = getEntriesSet(kind, false);
		if (set != null)
			return set.toArray();
		return new ICSettingEntry[0];
	}

	//	public String getId() {
	//		return fId;
	//	}

	@Override
	public ICSettingEntry[] getEntries() {
		List<ICSettingEntry> result = new ArrayList<ICSettingEntry>();
		int kinds[] = KindBasedStore.getAllEntryKinds();
		for (int i = 0; i < kinds.length; i++) {
			CEntriesSet list = getEntriesSet(kinds[i], false);
			if (list != null)
				result.addAll(Arrays.asList(list.toArray()));
		}

		return result.toArray(new ICSettingEntry[result.size()]);
	}
}

Back to the top