本文整理匯總了Java中org.eclipse.core.resources.IStorage類的典型用法代碼示例。如果您正苦於以下問題:Java IStorage類的具體用法?Java IStorage怎麽用?Java IStorage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
IStorage類屬於org.eclipse.core.resources包,在下文中一共展示了IStorage類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getUri
import org.eclipse.core.resources.IStorage; //導入依賴的package包/類
@Override
public URI getUri(IStorage storage) {
if (!uriValidator.isPossiblyManaged(storage)) {
return null;
}
URI uri = internalGetUri(storage);
if (null == uri) {
uri = super.getUri(storage);
}
if (uri != null && isValidUri(uri, storage)) {
return uri;
}
return null;
}
示例2: getStorages
import org.eclipse.core.resources.IStorage; //導入依賴的package包/類
@Override
public Iterable<Pair<IStorage, IProject>> getStorages(URI uri) {
if (uri.isArchive()) {
URIBasedStorage storage = new URIBasedStorage(uri);
String authority = uri.authority();
URI archiveFileURI = URI.createURI(authority.substring(0, authority.length() - 1));
Optional<? extends IN4JSEclipseProject> optionalProject = eclipseCore.findProject(archiveFileURI);
if (optionalProject.isPresent()) {
return Collections.singletonList(Tuples.<IStorage, IProject> create(storage, optionalProject.get()
.getProject()));
} else {
return Collections.singletonList(Tuples.create(storage, null));
}
} else {
return Collections.emptyList();
}
}
示例3: shouldGenerate
import org.eclipse.core.resources.IStorage; //導入依賴的package包/類
private boolean shouldGenerate(Resource resource, IProject aProject) {
try {
Iterable<Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(resource.getURI());
for (Pair<IStorage, IProject> pair : storages) {
if (pair.getFirst() instanceof IFile && pair.getSecond().equals(aProject)) {
IFile file = (IFile) pair.getFirst();
int findMaxProblemSeverity = file.findMaxProblemSeverity(null, true, IResource.DEPTH_INFINITE);
// If the generator itself placed an error marker on the resource, we have to ignore that error.
// Easiest way here is to remove that error marker-type and look for other severe errors once more:
if (findMaxProblemSeverity == IMarker.SEVERITY_ERROR) {
// clean
GeneratorMarkerSupport generatorMarkerSupport = injector
.getInstance(GeneratorMarkerSupport.class);
generatorMarkerSupport.deleteMarker(resource);
// and recompute:
findMaxProblemSeverity = file.findMaxProblemSeverity(null, true, IResource.DEPTH_INFINITE);
}
// the final decision to build:
return findMaxProblemSeverity != IMarker.SEVERITY_ERROR;
}
}
return false;
} catch (CoreException exc) {
throw new WrappedException(exc);
}
}
示例4: findSelection
import org.eclipse.core.resources.IStorage; //導入依賴的package包/類
@Override
public IStructuredSelection findSelection(final IEditorInput input) {
final IStructuredSelection selection = super.findSelection(input);
if (null == selection || selection.isEmpty() && input instanceof XtextReadonlyEditorInput) {
try {
final IStorage storage = ((XtextReadonlyEditorInput) input).getStorage();
if (storage instanceof URIBasedStorage) {
final URI uri = ((URIBasedStorage) storage).getURI();
if (uri.isFile()) {
final File file = new File(uri.toFileString());
if (file.exists() && file.isFile()) {
final Node node = getResourceNode(file);
if (null != node) {
return new StructuredSelection(node);
}
}
}
}
} catch (final CoreException e) {
LOGGER.error("Error while extracting storage from read-only Xtext editor input.", e);
return EMPTY;
}
}
return selection;
}
示例5: getShowInContext
import org.eclipse.core.resources.IStorage; //導入依賴的package包/類
/**
* Provides input so that the Project Explorer can locate the editor's input in its tree.
*/
@Override
public ShowInContext getShowInContext() {
IEditorInput editorInput = getEditorInput();
if (editorInput instanceof FileEditorInput) {
FileEditorInput fei = (FileEditorInput) getEditorInput();
return new ShowInContext(fei.getFile(), null);
} else if (editorInput instanceof XtextReadonlyEditorInput) {
XtextReadonlyEditorInput readOnlyEditorInput = (XtextReadonlyEditorInput) editorInput;
IStorage storage;
try {
storage = readOnlyEditorInput.getStorage();
return new ShowInContext(storage.getFullPath(), null);
} catch (CoreException e) {
// Do nothing
}
}
return new ShowInContext(null, null);
}
示例6: getFileFromStorageMapper
import org.eclipse.core.resources.IStorage; //導入依賴的package包/類
/**
* 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;
}
示例7: prepareMocksBase
import org.eclipse.core.resources.IStorage; //導入依賴的package包/類
/**
* Prepare mocks for all tests.
*/
public static void prepareMocksBase() {
oldDesc = mock(IResourceDescription.class);
newDesc = mock(IResourceDescription.class);
delta = mock(Delta.class);
resource = mock(Resource.class);
uriCorrect = mock(URI.class);
when(uriCorrect.isPlatformResource()).thenReturn(true);
when(uriCorrect.isFile()).thenReturn(true);
when(uriCorrect.toFileString()).thenReturn(DUMMY_PATH);
when(uriCorrect.toPlatformString(true)).thenReturn(DUMMY_PATH);
when(delta.getNew()).thenReturn(newDesc);
when(delta.getOld()).thenReturn(oldDesc);
when(delta.getUri()).thenReturn(uriCorrect);
when(resource.getURI()).thenReturn(uriCorrect);
file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(uriCorrect.toPlatformString(true)));
Iterable<Pair<IStorage, IProject>> storages = singleton(Tuples.<IStorage, IProject> create(file, file.getProject()));
mapperCorrect = mock(Storage2UriMapperImpl.class);
when(mapperCorrect.getStorages(uriCorrect)).thenReturn(storages);
}
示例8: getFileFromStorageMapper
import org.eclipse.core.resources.IStorage; //導入依賴的package包/類
/**
* Gets an {@link IFile} from the {@link IStorage2UriMapper} corresponding to given {@link URI}. If none
* could be found, <code>null</code> is returned.
*
* @param uri
* the URI
* @return the file from the storage to URI mapper or <code>null</code> if no match found
*/
private IFile getFileFromStorageMapper(final URI uri) {
if (storage2UriMapper == null) {
return null; // Should not occur
}
for (Pair<IStorage, IProject> storage : storage2UriMapper.getStorages(uri)) {
if (storage.getFirst() instanceof IFile) {
return (IFile) storage.getFirst();
}
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(MessageFormat.format("Could not find storage for URI {0}", uri.toString())); //$NON-NLS-1$
}
return null;
}
示例9: findFileStorage
import org.eclipse.core.resources.IStorage; //導入依賴的package包/類
/**
* 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;
}
}
示例10: internalGetUri
import org.eclipse.core.resources.IStorage; //導入依賴的package包/類
@Override
protected URI internalGetUri(IStorage storage) {
if (!uriValidator.isPossiblyManaged(storage))
return null;
URI uri = super.internalGetUri(storage);
if (uri != null)
return uri;
if (storage instanceof IJarEntryResource) {
final IJarEntryResource storage2 = (IJarEntryResource) storage;
Map<URI, IStorage> data = getAllEntries(storage2.getPackageFragmentRoot());
for (Map.Entry<URI, IStorage> entry : data.entrySet()) {
if (entry.getValue().equals(storage2))
return entry.getKey();
}
}
return null;
}
示例11: getLogicalURI
import org.eclipse.core.resources.IStorage; //導入依賴的package包/類
/**
* Converts the physical URI to a logic URI based on the bundle symbolic name.
*/
protected URI getLogicalURI(URI uri, IStorage storage, TraversalState state) {
if (bundleSymbolicName != null) {
URI logicalURI = URI.createPlatformResourceURI(bundleSymbolicName, false);
List<?> parents = state.getParents();
for (int i = 1; i < parents.size(); i++) {
Object obj = parents.get(i);
if (obj instanceof IPackageFragment) {
logicalURI = logicalURI.appendSegments(((IPackageFragment) obj).getElementName().split("\\."));
} else if (obj instanceof IJarEntryResource) {
logicalURI = logicalURI.appendSegment(((IJarEntryResource) obj).getName());
} else if (obj instanceof IFolder) {
logicalURI = logicalURI.appendSegment(((IFolder) obj).getName());
}
}
return logicalURI.appendSegment(uri.lastSegment());
}
return uri;
}
示例12: getAllEntries
import org.eclipse.core.resources.IStorage; //導入依賴的package包/類
/**
* @since 2.4
*/
public Map<URI, IStorage> getAllEntries(IContainer container) {
final Map<URI,IStorage> result = newLinkedHashMap();
try {
container.accept(new IResourceVisitor() {
public boolean visit(IResource resource) throws CoreException {
if (resource instanceof IFile) {
final IFile storage = (IFile) resource;
URI uri = getUri(storage);
if (uri != null)
result.put(uri, storage);
}
if (resource instanceof IFolder) {
return isHandled((IFolder)resource);
}
return true;
}
});
} catch (CoreException e) {
log.error(e.getMessage(), e);
}
return result;
}
示例13: canBuild
import org.eclipse.core.resources.IStorage; //導入依賴的package包/類
/**
* @since 2.4
*/
public boolean canBuild(URI uri, IStorage storage) {
if (uri == null)
return false;
IResourceServiceProvider resourceServiceProvider = registry.getResourceServiceProvider(uri);
if (resourceServiceProvider != null) {
if (resourceServiceProvider instanceof IResourceUIServiceProviderExtension) {
return ((IResourceUIServiceProviderExtension) resourceServiceProvider).canBuild(uri, storage);
} else if (resourceServiceProvider instanceof IResourceUIServiceProvider) {
return ((IResourceUIServiceProvider) resourceServiceProvider).canHandle(uri, storage);
} else {
return resourceServiceProvider.canHandle(uri);
}
}
return false;
}
示例14: initContainedURIs
import org.eclipse.core.resources.IStorage; //導入依賴的package包/類
public Collection<URI> initContainedURIs(String containerHandle) {
try {
IPath projectPath = new Path(null, containerHandle).makeAbsolute();
if (projectPath.segmentCount()!=1)
return Collections.emptySet();
IProject project = getWorkspaceRoot().getProject(containerHandle);
if (project != null && isAccessibleXtextProject(project)) {
Map<URI, IStorage> entries = getMapper().getAllEntries(project);
return entries.keySet();
}
} catch (IllegalArgumentException e) {
if (log.isDebugEnabled())
log.debug("Cannot init contained URIs for containerHandle '" + containerHandle + "'", e);
}
return Collections.emptyList();
}
示例15: getJarWithEntry
import org.eclipse.core.resources.IStorage; //導入依賴的package包/類
protected IPackageFragmentRoot getJarWithEntry(URI uri) {
Iterable<Pair<IStorage, IProject>> storages = getStorages(uri);
IPackageFragmentRoot result = null;
for (Pair<IStorage, IProject> storage2Project : storages) {
IStorage storage = storage2Project.getFirst();
if (storage instanceof IJarEntryResource) {
IPackageFragmentRoot fragmentRoot = ((IJarEntryResource) storage).getPackageFragmentRoot();
if (fragmentRoot != null) {
IJavaProject javaProject = fragmentRoot.getJavaProject();
if (isAccessibleXtextProject(javaProject.getProject()))
return fragmentRoot;
if (result != null)
result = fragmentRoot;
}
}
}
return result;
}