Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: adbb0655c37bd749bbdb562bf6f88ebd83cc4953 (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
/*******************************************************************************
 * Copyright (c) 2007, 2009 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
 *******************************************************************************/
package org.eclipse.cdt.internal.core.settings.model;

import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
import org.eclipse.cdt.core.settings.model.ICSettingBase;
import org.eclipse.cdt.core.settings.model.ICSettingContainer;
import org.eclipse.cdt.core.settings.model.ICSettingObject;
import org.eclipse.cdt.core.settings.model.WriteAccessException;
import org.eclipse.cdt.core.settings.model.extension.CFolderData;
import org.eclipse.cdt.core.settings.model.extension.CLanguageData;
import org.eclipse.cdt.core.settings.model.extension.impl.CDefaultFolderData;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.content.IContentType;

public class CFolderDescriptionCache extends CDefaultFolderData implements
		ICFolderDescription, ICachedData {
	private CConfigurationDescriptionCache fCfg;
	private ResourceDescriptionHolder fRcDesHolder;

	public CFolderDescriptionCache(CFolderData base, CConfigurationDescriptionCache cfg) {
		super(base.getId(), base.getPath(), cfg, null);
		fCfg = cfg;
		fCfg.addResourceDescription(this);
		
		copyDataFrom(base, true);
	}
	
	public ICLanguageSetting getLanguageSettingForFile(String fileName) {
		IProject project = getConfiguration().getProjectDescription().getProject();
		return CProjectDescriptionManager.getInstance().findLanguagSettingForFile(fileName, project, getLanguageSettings());
	}

	public ICLanguageSetting[] getLanguageSettings() {
		return fLanguageDatas.toArray(new CLanguageSettingCache[fLanguageDatas.size()]);
	}

	public ICResourceDescription getNestedResourceDescription(IPath relPath, boolean exactPath) {
		return getRcDesHolder().getResourceDescription(relPath, exactPath);
	}

	public ICResourceDescription[] getNestedResourceDescriptions(int kind) {
		return getRcDesHolder().getResourceDescriptions(kind);
	}

	public ICConfigurationDescription getConfiguration() {
		return fCfg;
	}

	public ICSettingContainer getParent() {
		return fCfg;
	}

	public ICSettingObject[] getChildSettings() {
		return getLanguageSettings();
	}

	@Override
	protected CLanguageData copyLanguageData(CLanguageData base, boolean clone) {
		return new CLanguageSettingCache(base, this);
	}

	public void setExcluded(boolean excluded) {
		throw ExceptionFactory.createIsReadOnlyException();
	}

	public boolean canExclude(boolean exclude) {
		return exclude == isExcluded();
	}

	@Override
	public void setPath(IPath path) throws WriteAccessException {
		throw ExceptionFactory.createIsReadOnlyException();
	}

	public void setName(String name) throws WriteAccessException {
		throw ExceptionFactory.createIsReadOnlyException();
	}
	
	public ICResourceDescription[] getNestedResourceDescriptions() {
		return getNestedResourceDescriptions(ICSettingBase.SETTING_FILE | ICSettingBase.SETTING_FOLDER);
	}
	
	private ResourceDescriptionHolder getRcDesHolder(){
		if(fRcDesHolder == null)
			fRcDesHolder = fCfg.createHolderForRc(getPath());
		return fRcDesHolder;
	}

	public boolean isReadOnly() {
		return true;
	}

	public ICFolderDescription getParentFolderDescription() {
		return getRcDesHolder().getParentFolderDescription();
	}

	public ICLanguageSetting createLanguageSetting(IContentType srcType) {
		throw ExceptionFactory.createIsReadOnlyException();
	}

	public ICLanguageSetting createLanguageSettingForContentTypes(
			String languageId, String[] typeIds) {
		throw ExceptionFactory.createIsReadOnlyException();
	}

	public ICLanguageSetting createLanguageSettingForExtensions(
			String languageId, String[] extensions) {
		throw ExceptionFactory.createIsReadOnlyException();
	}

	@Override
	public CLanguageData createLanguageDataForContentTypes(String languageId,
			String[] typesIds) {
		throw ExceptionFactory.createIsReadOnlyException();
	}

	@Override
	public CLanguageData createLanguageDataForExtensions(String languageId,
			String[] extensions) {
		throw ExceptionFactory.createIsReadOnlyException();
	}

	public boolean isRoot() {
		return getPath().segmentCount() == 0;
	}
	
	@Override
	public IPath getPath() {
		return ResourceDescriptionHolder.normalizePath(super.getPath());
	}

	@Override
	public boolean hasCustomSettings() {
		return true;
	}

	public boolean isExcluded() {
		return fCfg.isExcluded(getPath());
	}
}

Back to the top