blob: 207275b321d5365088ad44a92358c47e877750fe [file] [log] [blame]
/**
*
* 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 java.util.List
import org.eclipse.xtext.common.types.JvmPrimitiveType
import org.eclipse.xtext.common.types.JvmType
import org.eclipse.xtext.common.types.JvmVoid
import org.eclipse.xtext.common.types.access.impl.Primitives
import org.eclipse.xtext.common.types.xtext.AbstractTypeScope
import org.eclipse.xtext.naming.QualifiedName
import org.eclipse.xtext.resource.EObjectDescription
import org.eclipse.xtext.resource.IEObjectDescription
class PrimitiveAwareScope extends AbstractOXTypeTypeScope {
private AbstractTypeScope typeScope;
private AbstractOXTypeTypeScope parent;
new(AbstractOXTypeTypeScope parent, AbstractTypeScope typeScope) {
this.parent = parent;
this.typeScope = typeScope;
}
override IEObjectDescription getSingleElement(QualifiedName name) {
if (isPrimitive(name)) {
return typeScope.getSingleElement(name, true);
}
return parent.getSingleElement(name);
}
def boolean isPrimitive(QualifiedName name) {
return name.getSegmentCount() == 1 && Primitives.forName(name.getFirstSegment()) != null;
}
override void doGetElements(JvmType type, List<IEObjectDescription> result) {
if (type instanceof JvmVoid) {
result.add(EObjectDescription.create("void", type));
return;
}
if (type instanceof JvmPrimitiveType) {
result.add(EObjectDescription.create((type as JvmPrimitiveType).getSimpleName(), type));
return;
}
parent.doGetElements(type, result);
}
}