Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6e69f7d539a20b43ef9bf82ff3f2e6bb370be1b1 (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
/*******************************************************************************
 * 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.managedbuilder.internal.core;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.cdt.managedbuilder.buildproperties.IBuildProperty;
import org.eclipse.cdt.managedbuilder.buildproperties.IBuildPropertyType;
import org.eclipse.cdt.managedbuilder.buildproperties.IBuildPropertyValue;
import org.eclipse.cdt.managedbuilder.core.IBuildObjectProperties;
import org.eclipse.cdt.managedbuilder.core.IBuildPropertiesRestriction;
import org.eclipse.cdt.managedbuilder.internal.buildproperties.BuildProperties;
import org.eclipse.cdt.managedbuilder.internal.buildproperties.BuildPropertyManager;
import org.eclipse.core.runtime.CoreException;

public class BuildObjectProperties extends BuildProperties implements IBuildObjectProperties {
	private IBuildPropertiesRestriction fRestriction;
	private IBuildPropertyChangeListener fListener;

	public BuildObjectProperties(IBuildPropertiesRestriction restriction, IBuildPropertyChangeListener listener) {
		super();
		fRestriction = restriction;
		fListener = listener;
	}

	public BuildObjectProperties(BuildObjectProperties properties, IBuildPropertiesRestriction restriction,
			IBuildPropertyChangeListener listener) {
		super(properties);
		fRestriction = restriction;
		fListener = listener;
	}

	public BuildObjectProperties(String properties, IBuildPropertiesRestriction restriction,
			IBuildPropertyChangeListener listener) {
		super(properties);
		fRestriction = restriction;
		fListener = listener;
	}

	@Override
	public IBuildPropertyType[] getSupportedTypes() {
		IBuildPropertyType types[] = BuildPropertyManager.getInstance().getPropertyTypes();

		if (fRestriction != null && types.length != 0) {
			List<IBuildPropertyType> list = new ArrayList<>(types.length);
			for (IBuildPropertyType type : types) {
				if (fRestriction.supportsType(type.getId()))
					list.add(type);
			}

			types = list.toArray(new IBuildPropertyType[list.size()]);
		}

		return types;
	}

	@Override
	public IBuildPropertyValue[] getSupportedValues(String typeId) {
		IBuildPropertyType type = BuildPropertyManager.getInstance().getPropertyType(typeId);
		if (type != null) {
			IBuildPropertyValue values[] = type.getSupportedValues();
			if (fRestriction != null && values.length != 0) {
				List<IBuildPropertyValue> list = new ArrayList<>(values.length);
				for (IBuildPropertyValue value : values) {
					if (fRestriction.supportsValue(type.getId(), value.getId()))
						list.add(value);
				}

				return list.toArray(new IBuildPropertyValue[list.size()]);
			}
		}
		return new IBuildPropertyValue[0];
	}

	@Override
	public boolean supportsType(String id) {
		return fRestriction.supportsType(id);
		//		IBuildPropertyType type = BuildPropertyManager.getInstance().getPropertyType(id);
		//		if(type != null){
		//			if(fRestriction != null){
		//				return fRestriction.supportsType(type.getId());
		//			}
		//			return true;
		//		}
		//		return false;
	}

	@Override
	public boolean supportsValue(String typeId, String valueId) {
		return fRestriction.supportsValue(typeId, valueId);
		//		IBuildPropertyType type = BuildPropertyManager.getInstance().getPropertyType(typeId);
		//		if(type != null){
		//			IBuildPropertyValue value = type.getSupportedValue(valueId);
		//			if(value != null){
		//				if(fRestriction != null){
		//					return fRestriction.supportsValue(type.getId(), value.getId());
		//				}
		//				return true;
		//			}
		//		}
		//		return false;
	}

	@Override
	public void clear() {
		super.clear();
		fListener.propertiesChanged();
	}

	@Override
	public IBuildProperty removeProperty(String id) {
		IBuildProperty property = super.removeProperty(id);
		if (property != null)
			fListener.propertiesChanged();
		return property;
	}

	IBuildProperty internalSetProperty(String propertyId, String propertyValue) throws CoreException {
		return super.setProperty(propertyId, propertyValue);
	}

	@Override
	public IBuildProperty setProperty(String propertyId, String propertyValue) throws CoreException {
		//		if(!supportsType(propertyId))
		//			throw new CoreException(new Status(IStatus.ERROR,
		//					ManagedBuilderCorePlugin.getUniqueIdentifier(),
		//					"property type is not supported"));
		//		if(!supportsValue(propertyId, propertyValue))
		//			throw new CoreException(new Status(IStatus.ERROR,
		//					ManagedBuilderCorePlugin.getUniqueIdentifier(),
		//					"property value is not supported"));

		IBuildProperty property = super.setProperty(propertyId, propertyValue);
		fListener.propertiesChanged();
		return property;
	}

	@Override
	public String[] getRequiredTypeIds() {
		return fRestriction.getRequiredTypeIds();
	}

	@Override
	public boolean requiresType(String typeId) {
		return fRestriction.requiresType(typeId);
	}

	@Override
	public String[] getSupportedTypeIds() {
		return fRestriction.getSupportedTypeIds();
	}

	@Override
	public String[] getSupportedValueIds(String typeId) {
		return fRestriction.getSupportedValueIds(typeId);
	}
}

Back to the top