Java 类org.eclipse.xtext.ui.resource.IStorage2UriMapper 实例源码

项目:dsl-devkit    文件:CheckMarkerUpdateJob.java   
/**
 * 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
 * @param fileUri
 *          the URI
 * @return the file from the storage to URI mapper or <code>null</code> 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;
}
项目:dsl-devkit    文件:RuntimeProjectUtil.java   
/**
 * 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;
  }
}
项目:n4js    文件:BuildInstruction.java   
/**
 * 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;
}
项目:n4js    文件:N4JSClusteringBuilderConfiguration.java   
@Override
protected void configure() {
    bind(IResourceClusteringPolicy.class).to(N4JSVerboseClusteringPolicy.class);
    bind(XtextBuilder.class).to(N4JSBuildTypeTrackingBuilder.class);
    bind(ClusteringBuilderState.class).to(N4JSGenerateImmediatelyBuilderState.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);
}
项目:dsl-devkit    文件:CheckMarkerUpdateJob.java   
/**
 * Gets the resource set. Note that not all sources must be part of the same resource set.
 * 
 * @param storage2UriMapper
 *          the storage2 uri mapper
 * @param uri
 *          the uri
 * @return the resource set
 */
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;
}
项目:sadlos2    文件:SadlSharedModule.java   
@Override
    protected void configure() {
        bind(ToBeBuiltComputer.class).to(SadlToBeBuiltComputer.class);
        bind(ProjectClasspathChangeListener.class).asEagerSingleton();
        bind(IStorage2UriMapper.class).to(IStorage2UriMapperJdtExtensions.class);
        bind(IStorage2UriMapperJdtExtensions.class).to(Storage2UriMapperJavaImpl.class);
        bind(IResourceSetProvider.class).to(XtextResourceSetProvider.class);
//      bind(TypeResourceUnloader.class).asEagerSingleton();
        bind(JavaChangeQueueFiller.class).asEagerSingleton();
        bind(StorageAwareTrace.class).to(JarEntryAwareTrace.class);
        bind(DefaultTraceURIConverter.class).to(DefaultUITraceURIConverter.class);
    }
项目:dsl-devkit    文件:CheckMarkerUpdateJob.java   
/** {@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) {
          validate(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;
}
项目:bts    文件:AbstractStorage2UriMapperClient.java   
public void setMapper(IStorage2UriMapper mapper) {
    this.mapper = mapper;
}
项目:bts    文件:AbstractStorage2UriMapperClient.java   
public IStorage2UriMapper getMapper() {
    return mapper;
}
项目:bts    文件:XtextDocumentProvider.java   
/**
 * @since 2.4
 */
protected IStorage2UriMapper getStorage2UriMapper() {
    return storage2UriMapper;
}
项目:dsl-devkit    文件:ValidMarkerUpdateJob.java   
/**
 * 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;
}
项目:dsl-devkit    文件:RuntimeProjectUtil.java   
/**
 * 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();
}