blob: fdd9ab6a7d82b1429ee974a2b61c3d48f160dbb2 [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
*/
package org.eclipse.osbp.ecview.uisemantics.scoping;
import java.util.Collections;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.resource.EObjectDescription;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.scoping.IScope;
import org.eclipse.xtext.scoping.impl.SimpleScope;
import org.eclipse.xtext.xbase.scoping.batch.XbaseBatchScopeProvider;
import org.eclipse.osbp.ecview.semantic.uisemantics.UiSemanticsPackage;
import org.eclipse.osbp.ecview.semantic.uisemantics.UxElementURI;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
@SuppressWarnings("restriction")
public class ScopeProvider extends XbaseBatchScopeProvider {
@Override
public IScope getScope(EObject context, EReference reference) {
if (reference == UiSemanticsPackage.Literals.UX_EPACKAGE_IMPORT__EPACKAGE) {
return createEPackageScope();
} else if (reference == UiSemanticsPackage.Literals.UX_ELEMENT_URI__ECLASS) {
UxElementURI elementURI = (UxElementURI) context;
return new EPackageContentScope(elementURI.getEPackage()
.getEPackage());
}
return super.getScope(context, reference);
}
protected IScope createEPackageScope() {
IScope current = new SimpleScope(IScope.NULLSCOPE, Iterables.transform(
EPackage.Registry.INSTANCE.keySet(),
new Function<String, IEObjectDescription>() {
public IEObjectDescription apply(String from) {
InternalEObject proxyPackage = (InternalEObject) EcoreFactory.eINSTANCE
.createEPackage();
proxyPackage.eSetProxyURI(URI.createURI(from));
return EObjectDescription.create(
QualifiedName.create(from), proxyPackage,
Collections.singletonMap("nsURI", "true"));
}
}));
return current;
}
}