Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5ceb7ea8d2614d37e9a5bf9538ed857d8c77ab18 (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
/**
 *                                                                            
 * Copyright (c) 2011, 2015 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
 * All rights reserved. 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:
 *         Florian Pirchner - Initial implementation
 *   
 *  This copyright notice shows up in the generated Java code
 *
 */
package org.eclipse.osbp.xtext.oxtype.scoping.jvmtype

import com.google.common.collect.Maps
import java.util.Collections
import java.util.List
import java.util.Map
import org.eclipse.xtext.common.types.JvmType
import org.eclipse.xtext.naming.QualifiedName
import org.eclipse.xtext.resource.IEObjectDescription

class CachingTypeScope extends AbstractOXTypeTypeScope {

	private final AbstractOXTypeTypeScope parent;
	private final Map<QualifiedName, IEObjectDescription> cache;

	new(AbstractOXTypeTypeScope parent) {
		this.parent = parent;
		this.cache = Maps.newHashMapWithExpectedSize(50);
	}

	override IEObjectDescription getSingleElement(QualifiedName name) {
		var IEObjectDescription cached = cache.get(name);
		if (cached == null) {
			if (cache.containsKey(name)) {
				return null;
			}
			cached = parent.getSingleElement(name);
			cache.put(name, cached);
		}
		return cached;
	}

	override Iterable<IEObjectDescription> getElements(QualifiedName name) {
		var IEObjectDescription element = getSingleElement(name);
		if (element == null)
			return Collections.emptyList();
		return Collections.singletonList(element);
	}

	override void doGetElements(JvmType type, List<IEObjectDescription> result) {
		parent.doGetElements(type, result);
	}

}

Back to the top