Created
September 21, 2012 11:50
-
-
Save digulla/3761048 to your computer and use it in GitHub Desktop.
A global scope provider that is both able to process the importURI attributes to establish cross links with other EMF models, and to handle references to JVM types.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.eclipse.emf.ecore.EReference; | |
import org.eclipse.emf.ecore.resource.Resource; | |
import org.eclipse.xtext.EcoreUtil2; | |
import org.eclipse.xtext.common.types.TypesPackage; | |
import org.eclipse.xtext.common.types.xtext.AbstractTypeScopeProvider; | |
import org.eclipse.xtext.common.types.xtext.ClasspathBasedTypeScopeProvider; | |
import org.eclipse.xtext.common.types.xtext.TypesAwareDefaultGlobalScopeProvider; | |
import org.eclipse.xtext.resource.IEObjectDescription; | |
import org.eclipse.xtext.scoping.IScope; | |
import org.eclipse.xtext.scoping.impl.ImportUriGlobalScopeProvider; | |
import com.google.common.base.Predicate; | |
import com.google.inject.Inject; | |
/** | |
* A global scope provider that is both able to process the importURI attributes to establish cross links | |
* with other EMF models, and to handle references to JVM types. | |
* | |
* <p>This class is a subclass of {@link ImportUriGlobalScopeProvider} in order to get the importURI behavior | |
* and delegates references to JVM types to an instance of AbstractTypeScopeProvider obtained through Guice. | |
* | |
* @see TypesAwareDefaultGlobalScopeProvider where part of is getScope() function is duplicated here. | |
* @see ClasspathBasedTypeScopeProvider | |
* @see org.eclipse.xtext.common.types.xtext.ui.JdtBasedSimpleTypeScopeProvider | |
* | |
*/ | |
@SuppressWarnings( "restriction" ) | |
public class TypeAndImportUriGlobalScopeProvider extends ImportUriGlobalScopeProvider { | |
/* | |
* AbstractTypeScopeProvider is bound to org.eclipse.xtext.common.types.xtext.ClasspathBasedTypeScopeProvider | |
* in the "Standalone" setup and to org.eclipse.xtext.common.types.xtext.ui.JdtBasedSimpleTypeScopeProvider | |
* int the IU setup. In both cases, the class AbstractTypeScopeProvider which is the usual global | |
* scope provider when using the JVM types uses an AbstractTypeScopeProvider instance (through Guice) to | |
* handle all references to JVM types : we do the same here. | |
*/ | |
@Inject | |
private AbstractTypeScopeProvider typeScopeProvider; | |
@Override | |
public IScope getScope( Resource resource, EReference reference, Predicate<IEObjectDescription> filter ) { | |
if( EcoreUtil2.isAssignableFrom( TypesPackage.Literals.JVM_TYPE, reference.getEReferenceType() ) ) { | |
IScope typeScope = typeScopeProvider.getScope( resource, reference, filter ); | |
return typeScope; | |
} | |
else { | |
return super.getScope( resource, reference, filter ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment