org.eclipse.xtext.ui.resource.IStorage2UriMapper Java Examples

The following examples show how to use org.eclipse.xtext.ui.resource.IStorage2UriMapper. 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: N4JSClusteringBuilderConfiguration.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void configure() {
	bind(IResourceClusteringPolicy.class).to(VerboseClusteringPolicy.class);
	bind(XtextBuilder.class).to(N4JSBuildTypeTrackingBuilder.class);
	bind(IBuilderState.class).to(N4JSGenerateImmediatelyBuilderState.class).in(Scopes.SINGLETON);
	bind(IMarkerUpdater.class).to(N4JSMarkerUpdater.class);
	bind(IStorage2UriMapper.class).to(N4JSStorage2UriMapper.class);
	bind(PersistedStateProvider.class).to(ContributingResourceDescriptionPersister.class);
	bind(IBuildLogger.class).annotatedWith(BuilderState.class).to(BuilderStateLogger.class);
	bind(DirtyStateManager.class).to(PrevStateAwareDirtyStateManager.class);
	bind(IResourceLoader.class).annotatedWith(
			Names.named(ClusteringBuilderState.RESOURCELOADER_GLOBAL_INDEX)).toProvider(
					new BuildScopeAwareParallelLoaderProvider());
	bind(BuilderStateDiscarder.class);
	bind(SharedStateContributionRegistryImpl.class).to(DefaultSharedContributionOverridingRegistry.class);
	binder().install(new MyReferenceSearchResultContentProviderCustomModule());
}
 
Example #2
Source File: JavaProjectsStateTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected JavaProjectsState createProjectsState(IStorage2UriMapper mapper) {
	JavaProjectsState result = new JavaProjectsState();
	result.setMapper(mapper);
	result.setJdtHelper(new JdtHelper());
	result.setJavaProjectClasspathChangeAnalyzer(new JavaProjectClasspathChangeAnalyzer());
	JavaProjectsStateHelper javaProjectsStateHelper = new JavaProjectsStateHelper();
	javaProjectsStateHelper.setMapper(mapper);
	javaProjectsStateHelper.setUriMapperExtensions((IStorage2UriMapperJdtExtensions) ((Storage2UriMapperImpl)mapper).getContribution());
	javaProjectsStateHelper.setWorkspace(ResourcesPlugin.getWorkspace());
	result.setJavaProjectsHelper(javaProjectsStateHelper);
	WorkspaceProjectsStateHelper workspaceStateHelper = new WorkspaceProjectsStateHelper();
	workspaceStateHelper.setMapper(mapper);
	workspaceStateHelper.setWorkspace(ResourcesPlugin.getWorkspace());
	result.setProjectsHelper(workspaceStateHelper);
	return result;
}
 
Example #3
Source File: RuntimeProjectUtil.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the file {@link IFile} based on its {@link URI}.
 *
 * @param uri
 *          the URI of the resource for which an IFile is to be returned
 * @param mapper
 *          class returning e.g. set of storages {@link IStorage} matching given URI; injected by concrete BuilderParticipant
 * @return the file associated with given URI
 */
public static IFile findFileStorage(final URI uri, final IStorage2UriMapper mapper) {
  Iterable<Pair<IStorage, IProject>> storages = mapper.getStorages(uri);
  try {
    Pair<IStorage, IProject> fileStorage = Iterables.find(storages, new Predicate<Pair<IStorage, IProject>>() {
      @Override
      public boolean apply(final Pair<IStorage, IProject> input) {
        IStorage storage = input.getFirst();
        if (storage instanceof IFile) {
          return true;
        }
        return false;
      }
    });

    return (IFile) fileStorage.getFirst();
  } catch (NoSuchElementException e) {
    LOGGER.debug("Cannot find file storage for " + uri); //$NON-NLS-1$
    return null;
  }
}
 
Example #4
Source File: CheckMarkerUpdateJob.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Gets an {@link IFile} from the {@link IStorage2UriMapper} corresponding to given {@link URI}. If none
 * could be found, <code>null</code> is returned.
 *
 * @param storage2UriMapper
 *          the storage to URI mapper, may be {@code null}
 * @param fileUri
 *          the URI, must not be {@code null}
 * @return the file from the storage to URI mapper, or {@code null} if no match found
 */
private IFile getFileFromStorageMapper(final IStorage2UriMapper storage2UriMapper, final URI fileUri) {
  if (storage2UriMapper == null) {
    return null; // Should not occur
  }

  for (Pair<IStorage, IProject> storage : storage2UriMapper.getStorages(fileUri)) {
    if (storage.getFirst() instanceof IFile) {
      return (IFile) storage.getFirst();
    }
  }
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug(MessageFormat.format("Could not find storage for URI {0}", fileUri.toString())); //$NON-NLS-1$
  }
  return null;
}
 
Example #5
Source File: WorkbenchResolutionAdaptorRunTest.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void configure() {
  bind(String.class).annotatedWith(Names.named(Constants.LANGUAGE_NAME)).toInstance("com.avaloq.tools.dsl.TestLang"); //$NON-NLS-1$
  bind(IWorkbench.class).toInstance(mock(IWorkbench.class));
  bind(IResourceDescriptions.class).toInstance(mock(IResourceDescriptions.class));
  bind(IWorkspace.class).toInstance(mock(IWorkspace.class));

  bind(IModificationContextRegistry.class).toInstance(mock(IModificationContextRegistry.class));

  bind(WorkbenchMarkerResolutionGenerator.RegistryProvider.class).toInstance(mockRegistryProvider);
  bind(IStorage2UriMapper.class).toInstance(mockStorage2UriMapper);
  bind(ILanguageResourceHelper.class).toInstance(mockLanguageResourceHelper);
  bind(IssueResolutionProvider.class).toInstance(mockIssueResolutionProvider);

  bind(IResourceSetProvider.class).toInstance(mockResourceSetProvider);
  bind(IDirtyStateManager.class).toInstance(mockDirtyStateManager);
}
 
Example #6
Source File: StrictJavaProjectsStateTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected StrictJavaProjectsState createProjectsState(IStorage2UriMapper mapper) {
	StrictJavaProjectsState result = new StrictJavaProjectsState();
	result.setMapper(mapper);
	result.setJdtHelper(new JdtHelper());
	result.setJavaProjectClasspathChangeAnalyzer(new JavaProjectClasspathChangeAnalyzer());
	JavaProjectsStateHelper javaProjectsStateHelper = new JavaProjectsStateHelper();
	javaProjectsStateHelper.setMapper(mapper);
	javaProjectsStateHelper.setUriMapperExtensions((IStorage2UriMapperJdtExtensions) ((Storage2UriMapperImpl)mapper).getContribution());
	javaProjectsStateHelper.setWorkspace(ResourcesPlugin.getWorkspace());
	result.setHelper(javaProjectsStateHelper);
	return result;
}
 
Example #7
Source File: CheckMarkerUpdateJob.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gets the resource set. Note that not all sources must be part of the same resource set.
 *
 * @param storage2UriMapper
 *          the storage2 uri mapper, must not be {@code null}
 * @param uri
 *          the uri, must not be {@code null}
 * @return the resource set, may be {@code null}
 */
private ResourceSet getResourceSet(final IStorage2UriMapper storage2UriMapper, final URI uri) {
  Iterable<Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(uri);
  if (!Iterables.isEmpty(storages)) {
    IProject project = Iterables.get(storages, 0).getSecond();
    XtextResourceSetProvider resourceSetProvider = this.serviceProviderRegistry.getResourceServiceProvider(uri).get(XtextResourceSetProvider.class);
    return resourceSetProvider.get(project);
  }
  return null;
}
 
Example #8
Source File: BuildInstruction.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Create a build instruction for the given project.
 */
public BuildInstruction(IProject project,
		Map<String, OutputConfiguration> outputConfigurations,
		IDerivedResourceMarkers derivedResourceMarkers,
		EclipseResourceFileSystemAccess2 access,
		Map<OutputConfiguration, Iterable<IMarker>> generatorMarkers,
		IStorage2UriMapper storage2UriMapper, ICompositeGenerator compositeGenerator,
		Injector injector) {
	super(project, outputConfigurations, derivedResourceMarkers);
	this.access = access;
	this.generatorMarkers = generatorMarkers;
	this.storage2UriMapper = storage2UriMapper;
	this.compositeGenerator = compositeGenerator;
	this.injector = injector;
}
 
Example #9
Source File: TraceEditor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected IStorage getLocalStorage(IResourceServiceProvider serviceProvider, URI traceURI) {
	TraceFileNameProvider fileNameProvider = serviceProvider.get(TraceFileNameProvider.class);
	IStorage2UriMapper storage2UriMapper = serviceProvider.get(IStorage2UriMapper.class);
	String generatedName = fileNameProvider.getJavaFromTrace(traceURI.lastSegment());
	URI generatedURI = traceURI.trimSegments(1).appendSegment(generatedName);
	for (Pair<IStorage, IProject> x : storage2UriMapper.getStorages(generatedURI))
		return x.getFirst();
	throw new IllegalStateException("Could not find IStorage for " + generatedURI);
}
 
Example #10
Source File: XtextDocumentProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.4
 */
protected IStorage2UriMapper getStorage2UriMapper() {
	return storage2UriMapper;
}
 
Example #11
Source File: CheckMarkerUpdateJob.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
protected IStatus run(final IProgressMonitor monitor) {

  // Let's start (number of task = number of resource * 2 (loading + validating))
  monitor.beginTask("", 2 * this.uris.size()); //$NON-NLS-1$

  for (final URI uri : this.uris) {
    // Last chance to cancel before next validation
    if (monitor.isCanceled()) {
      return Status.CANCEL_STATUS;
    }

    final IResourceServiceProvider serviceProvider = serviceProviderRegistry.getResourceServiceProvider(uri);
    if (serviceProvider == null) {
      // This may happen for non-Xtext resources in ice entities
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(MessageFormat.format("Could not validate {0}: no resource service provider found", uri.toString())); //$NON-NLS-1$
      }
      continue; // Skip to next URI
    }

    final IResourceValidator resourceValidator = serviceProvider.getResourceValidator();
    final IStorage2UriMapper uriMapper = serviceProvider.get(IStorage2UriMapper.class);
    final MarkerCreator markerCreator = serviceProvider.get(MarkerCreator.class);

    // Get the file; only local files will be re-validated, derived files are ignored
    final IFile iFile = getFileFromStorageMapper(uriMapper, uri);
    if (iFile == null) {
      continue; // no storage mapping found for this URI
    }

    if (resourceValidator == null) {
      LOGGER.error(MessageFormat.format("Could not validate {0}: no resource validator found", iFile.getName())); //$NON-NLS-1$
    } else if (iFile != null) {
      monitor.subTask("loading " + iFile.getName()); //$NON-NLS-1$

      // Don't try to evaluate resource set before it has been checked that the storage provider contains a mapping
      // for current uri
      final ResourceSet resourceSet = getResourceSet(uriMapper, uri);

      // Load the corresponding resource
      boolean loaded = false;
      Resource eResource = null;
      try {
        eResource = resourceSet.getResource(uri, false);
        if ((eResource == null) || (eResource != null && !eResource.isLoaded())) {
          // if the resource does not exist in the resource set, or is not loaded yet
          // load it.
          eResource = resourceSet.getResource(uri, true);
          loaded = true;
        }
        monitor.worked(1);
        // CHECKSTYLE:OFF
      } catch (final RuntimeException e) {
        // CHECKSTYLE:ON
        LOGGER.error(MessageFormat.format("{0} could not be validated.", iFile.getName()), e); //$NON-NLS-1$
      } finally {
        if (eResource != null) {
          validateAndCreateMarkers(resourceValidator, markerCreator, iFile, eResource, monitor);
          LOGGER.debug("Validated " + uri); //$NON-NLS-1$
          if (loaded) { // NOPMD
            // unload any resource that was previously loaded as part of this loop.
            eResource.unload();
          }
        }
      }
    }
  }

  monitor.done();

  return Status.OK_STATUS;
}
 
Example #12
Source File: QueuedBuildData.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Public for testing purpose
 * 
 * @noreference This constructor is not intended to be referenced by clients.
 */
public QueuedBuildData(IStorage2UriMapper mapper, IQueuedBuildDataContribution contribution) {
	this.mapper = mapper;
	this.contribution = contribution;
	reset();
}
 
Example #13
Source File: QueuedBuildData.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Inject
public QueuedBuildData(IStorage2UriMapper mapper) {
	this.mapper = mapper;
	reset();
}
 
Example #14
Source File: BuilderParticipant.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.7
 */
public IStorage2UriMapper getStorage2UriMapper() {
	return storage2UriMapper;
}
 
Example #15
Source File: JavaClassPathResourceForIEditorInputFactory.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.5
 */
public IStorage2UriMapper getStorageToUriMapper() {
	return storageToUriMapper;
}
 
Example #16
Source File: AbstractStorage2UriMapperClient.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public IStorage2UriMapper getMapper() {
	return mapper;
}
 
Example #17
Source File: AbstractStorage2UriMapperClient.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public void setMapper(IStorage2UriMapper mapper) {
	this.mapper = mapper;
}
 
Example #18
Source File: AbstractEclipseTrace.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected IStorage2UriMapper getStorage2uriMapper() {
	return storage2uriMapper;
}
 
Example #19
Source File: SharedStateModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Provider<IStorage2UriMapper> provideIStorage2UriMapper() {
	return Access.getIStorage2UriMapper();
}
 
Example #20
Source File: Access.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public static Provider<IStorage2UriMapper> getIStorage2UriMapper() {
	return provider(IStorage2UriMapper.class);
}
 
Example #21
Source File: ValidMarkerUpdateJob.java    From dsl-devkit with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Instantiates a new valid marker update job.
 *
 * @param name
 *          the name
 * @param fileExtensions
 *          the file extensions
 * @param resourceSet
 *          the resource set
 * @param markerCreator
 *          the marker creator
 * @param resourceDescriptions
 *          the resource descriptions
 * @param resourceServiceProvider
 *          the resource service provider
 * @param performExpensiveValidation
 *          true if expensive validation should be performed, false otherwise
 */
public ValidMarkerUpdateJob(final String name, final String fileExtensions, final ResourceSet resourceSet, final MarkerCreator markerCreator, final IResourceDescriptions resourceDescriptions, final IResourceServiceProvider resourceServiceProvider, final boolean performExpensiveValidation, final IStorage2UriMapper storage2UriMapper) {
  super(name + " " + fileExtensions); //$NON-NLS-1$

  this.fileExtensions = fileExtensions;
  this.resourceSet = resourceSet;
  this.markerCreator = markerCreator;
  this.resourceDescriptions = resourceDescriptions;
  this.resourceServiceProvider = resourceServiceProvider;
  this.performExpensiveValidation = performExpensiveValidation;
  this.checkMode = performExpensiveValidation ? CheckMode.ALL : CheckMode.NORMAL_AND_FAST;
  this.storage2UriMapper = storage2UriMapper;
}
 
Example #22
Source File: RuntimeProjectUtil.java    From dsl-devkit with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Returns the project containing the file indicated by a URI.
 *
 * @param uri
 *          URI containing path from which the project name is extracted
 * @param mapper
 *          class returning e.g. set of storages {@link IStorage} matching given URI; injected by concrete BuilderParticipant
 * @return project {@link IProject} associated with given URI
 */
public static IProject getProject(final URI uri, final IStorage2UriMapper mapper) {
  final IFile file = findFileStorage(uri, mapper);
  return file == null ? null : file.getProject();
}
 
Example #23
Source File: AbstractJavaProjectsStateTest.java    From xtext-eclipse with Eclipse Public License 2.0 votes vote down vote up
protected abstract AbstractJavaProjectsState createProjectsState(IStorage2UriMapper mapper);