| /** |
| * |
| * 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); |
| } |
| |
| } |