use of org.eclipse.n4js.utils.ResourceType in project n4js by eclipse.
the class SourceGraphView method showGraph.
/**
* Create a new graph for the given resource set (using an {@link ASTGraphProvider}), add it to the history and show
* it in the view.
* <p>
* Need not be invoked from the UI thread.
*
* @param label
* the label for the new graph.
* @param root
* the root object to create the graph from; must be a {@link ResourceSet}, {@link Resource}, or
* {@link EObject}.
*/
public <GP extends GraphProvider<?, ?>> void showGraph(String label, Graph<GP> graph, GraphType graphType, GP graphProvider, Object root) {
if (!(root instanceof ResourceSet || root instanceof Resource || root instanceof EObject))
throw new IllegalArgumentException("root must be a ResourceSet, Resource, or EObject");
if (graphList.isDisposed())
return;
ResourceType resourceType = null;
if (root instanceof ResourceSet) {
ResourceSet rs = (ResourceSet) root;
if (rs.getResources().isEmpty()) {
return;
}
resourceType = ResourceType.getResourceType(rs.getResources().get(0));
}
if (root instanceof Resource) {
Resource rs = (Resource) root;
resourceType = ResourceType.getResourceType(rs);
}
if (root instanceof EObject) {
EObject eo = (EObject) root;
resourceType = ResourceType.getResourceType(eo);
}
if (resourceType != null) {
boolean supportedCFG = false;
supportedCFG |= resourceType == ResourceType.JS;
supportedCFG |= resourceType == ResourceType.JSX;
supportedCFG |= resourceType == ResourceType.N4JS;
supportedCFG |= resourceType == ResourceType.N4JSX;
if (supportedCFG) {
graph.build(graphProvider, root);
showGraph(label, graph, graphType);
}
}
}
use of org.eclipse.n4js.utils.ResourceType in project n4js by eclipse.
the class N4HeadlessCompiler method shouldIndexResource.
/**
* Indicates whether or not the given resource should be indexed.
*
* @param resource
* the resource to be indexed
* @return <code>true</code> if the given resource should be indexed and <code>false</code> otherwise
*/
private boolean shouldIndexResource(Resource resource) {
final URI uri = resource.getURI();
final ResourceType resourceType = ResourceType.getResourceType(uri);
// We only want to index raw JS files if they are contained in an N4JS source container.
switch(resourceType) {
case JS:
return n4jsCore.findN4JSSourceContainer(uri).isPresent();
case JSX:
return n4jsCore.findN4JSSourceContainer(uri).isPresent();
case UNKOWN:
return false;
default:
return true;
}
}
Aggregations