Java Code Examples for org.eclipse.xtext.EcoreUtil2#getResourceSet()

The following examples show how to use org.eclipse.xtext.EcoreUtil2#getResourceSet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractXbaseCompiler.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected JvmType findKnownTopLevelType(Class<?> rawType, Notifier context) {
	if (rawType.isArray()) {
		throw new IllegalArgumentException(rawType.getCanonicalName());
	}
	if (rawType.isPrimitive()) {
		throw new IllegalArgumentException(rawType.getName());
	}
	ResourceSet resourceSet = EcoreUtil2.getResourceSet(context);
	if (resourceSet == null) {
		return null;
	}
	Resource typeResource = resourceSet.getResource(URIHelperConstants.OBJECTS_URI.appendSegment(rawType.getName()), true);
	List<EObject> resourceContents = typeResource.getContents();
	if (resourceContents.isEmpty())
		return null;
	JvmType type = (JvmType) resourceContents.get(0);
	return type;
}
 
Example 2
Source File: AbstractXbaseCompiler.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected JvmType findKnownType(Class<?> rawType, Notifier context) {
	if (rawType.isArray()) {
		throw new IllegalArgumentException(rawType.getCanonicalName());
	}
	if (rawType.isPrimitive()) {
		throw new IllegalArgumentException(rawType.getName());
	}		ResourceSet resourceSet = EcoreUtil2.getResourceSet(context);
	if (resourceSet == null) {
		return null;
	}
	Class<?> declaringClass = rawType.getDeclaringClass();
	if (declaringClass == null) {
		return findKnownTopLevelType(rawType, resourceSet);
	}
	JvmType result = (JvmType) resourceSet.getEObject(URIHelperConstants.OBJECTS_URI.appendSegment(declaringClass.getName()).appendFragment(rawType.getName()), true);
	return result;
}
 
Example 3
Source File: XFunctionTypeRefImplCustom.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected JvmTypeReference getJavaLangObjectTypeRef(JvmType rawType, TypesFactory typesFactory) {
	ResourceSet rs = EcoreUtil2.getResourceSet(rawType);
	JvmParameterizedTypeReference refToObject = typesFactory.createJvmParameterizedTypeReference();
	if (rs != null) {
		EObject javaLangObject = rs.getEObject(javaLangObjectURI, true);
		if (javaLangObject instanceof JvmType) {
			JvmType objectDeclaration = (JvmType) javaLangObject;
			refToObject.setType(objectDeclaration);
			return refToObject;
		}
	}
	JvmGenericType proxy = typesFactory.createJvmGenericType();
	((InternalEObject)proxy).eSetProxyURI(javaLangObjectURI);
	refToObject.setType(proxy);
	return refToObject;
}
 
Example 4
Source File: TypeReferences.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * looks up a JVMType corresponding to the given {@link Class}. This method ignores any Jvm types created in non-
 * {@link TypeResource} in the given context's resourceSet, but goes straight to the Java-layer, using a
 * {@link IJvmTypeProvider}.
 * 
 * @return the JvmType with the same qualified name as the given {@link Class} object, or null if no such JvmType
 *         could be found using the context's resourceSet.
 */
public JvmType findDeclaredType(String typeName, Notifier context) {
	if (typeName == null)
		throw new NullPointerException("typeName");
	if (context == null)
		throw new NullPointerException("context");
	ResourceSet resourceSet = EcoreUtil2.getResourceSet(context);
	if (resourceSet == null)
		return null;
	// make sure a type provider is configured in the resource set. 
	IJvmTypeProvider typeProvider = typeProviderFactory.findOrCreateTypeProvider(resourceSet);
	try {
		final JvmType result = typeProvider.findTypeByName(typeName);
		return result;
	} catch (RuntimeException e) {
		operationCanceledManager.propagateAsErrorIfCancelException(e);
		log.info("Couldn't find JvmType for name '" + typeName + "' in context " + context, e);
		return null;
	}
}
 
Example 5
Source File: AnnotationLookup.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
private JvmAnnotationType findAnnotationType(Class<? extends Annotation> type, Notifier context) {
	ResourceSet resourceSet = EcoreUtil2.getResourceSet(context);
	if (resourceSet == null)
		return null;
	IJvmTypeProvider typeProvider = typeProviderFactory.findOrCreateTypeProvider(resourceSet);
	try {
		final JvmType result = typeProvider.findTypeByName(type.getName());
		if (result instanceof JvmAnnotationType)
			return (JvmAnnotationType) result;
		return null;
	} catch (RuntimeException e) {
		return null;
	}
}
 
Example 6
Source File: CompilerPhases.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public boolean isIndexing(Notifier ctx) {
	ResourceSet set = EcoreUtil2.getResourceSet(ctx);
	if (set != null) {
		return EcoreUtil.getAdapter(set.eAdapters(), IndexingAdapter.INSTANCE) != null;
	}
	return false;
}
 
Example 7
Source File: CompilerPhases.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void setIndexing(Notifier ctx, boolean isIndex) {
	ResourceSet set = EcoreUtil2.getResourceSet(ctx);
	if (isIndex) {
		set.eAdapters().add(IndexingAdapter.INSTANCE);
	} else {
		set.eAdapters().remove(IndexingAdapter.INSTANCE);
	}
}
 
Example 8
Source File: ResourceSetBasedResourceDescriptions.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setContext(Notifier ctx) {
	this.resourceSet = EcoreUtil2.getResourceSet(ctx);
	if (resourceSet != null) {
		data = ResourceDescriptionsData.ResourceSetAdapter.findResourceDescriptionsData(resourceSet);
	}
}
 
Example 9
Source File: LiveShadowedChunkedResourceDescriptions.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setContext(Notifier ctx) {
	ResourceSetBasedResourceDescriptions localDescriptions = (ResourceSetBasedResourceDescriptions) getLocalDescriptions();
	localDescriptions.setContext(ctx);
	localDescriptions.setData(null);
	ResourceSet resourceSet = EcoreUtil2.getResourceSet(ctx);
	setGlobalDescriptions(ChunkedResourceDescriptions.findInEmfObject(resourceSet));
	if (projectConfigProvider == null) {
		workspaceConfig = null;
	} else {
		IProjectConfig projectConfig = projectConfigProvider.getProjectConfig(resourceSet);
		workspaceConfig = projectConfig == null ? null : projectConfig.getWorkspaceConfig();
	}
}
 
Example 10
Source File: CurrentDescriptions2.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Set the context.
 * 
 * @param ctx
 *          The context
 */
@Override
public void setContext(final Notifier ctx) {
  super.setContext(ctx);
  final ResourceSet resourceSet = EcoreUtil2.getResourceSet(ctx);
  IResourceDescriptions adapter = (IResourceDescriptions) EcoreUtil2.getAdapter(resourceSet.eAdapters(), CurrentDescriptions.class);
  if (adapter instanceof IResourceDescriptions2) {
    delegate = (IResourceDescriptions2) adapter;
  } else {
    delegate = new ResourceDescriptions2(adapter);
  }
}
 
Example 11
Source File: SARLGeneratorConfigProvider.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public GeneratorConfig get(EObject context) {
	// Search for the Eclipse configuration
	final ResourceSet resourceSet = EcoreUtil2.getResourceSet(context);
	if (resourceSet != null) {
		final GeneratorConfigProvider.GeneratorConfigAdapter adapter =
				GeneratorConfigProvider.GeneratorConfigAdapter.findInEmfObject(resourceSet);
		if (adapter != null && adapter.getLanguage2GeneratorConfig().containsKey(this.languageId)) {
			return adapter.getLanguage2GeneratorConfig().get(this.languageId);
		}
	}
	// Create the default configuration
	final GeneratorConfig config = createDefaultGeneratorConfig();
	return config;
}
 
Example 12
Source File: EagerResourceSetBasedResourceDescriptions.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void setContext(Notifier ctx) {
	this.resourceSet = EcoreUtil2.getResourceSet(ctx);
}
 
Example 13
Source File: EagerResourceSetBasedResourceDescriptions.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void setContext(Notifier ctx) {
	this.resourceSet = EcoreUtil2.getResourceSet(ctx);
}
 
Example 14
Source File: ResourceSetContext.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public static ResourceSetContext get(Notifier context) {
	ResourceSet resourceSet = EcoreUtil2.getResourceSet(context);
	return new ResourceSetContext(resourceSet);
}
 
Example 15
Source File: CurrentDescriptions.java    From xtext-eclipse with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Set the context.
 * 
 * @param ctx
 *            The context
 */
@Override
public void setContext(Notifier ctx) {
	final ResourceSet resourceSet = EcoreUtil2.getResourceSet(ctx);
	delegate = (IResourceDescriptions) EcoreUtil.getAdapter(resourceSet.eAdapters(), CurrentDescriptions.class);
}