org.eclipse.core.resources.IStorage Java Examples
The following examples show how to use
org.eclipse.core.resources.IStorage.
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: UiBinderJavaValidator.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
private Set<IPath> getUiXmlWorkspaceRelativePaths( TypeDeclaration ownerTypeDecl) { Set<IPath> paths = new HashSet<IPath>(); String ownerTypeName = ownerTypeDecl.resolveBinding().getQualifiedName(); for (IType uiBinderSubtype : uiBinderToOwner.getUiBinderTypes(ownerTypeName)) { IPath uiXmlClasspathRelativePath = ownerToUiXml.getUiXmlPath(uiBinderSubtype); try { IStorage uiXmlFile = ClasspathResourceUtilities.resolveFile( uiXmlClasspathRelativePath, javaProject); // Verify that the ui.xml exists and is not in a JAR if (uiXmlFile instanceof IFile) { paths.add(uiXmlFile.getFullPath()); } } catch (JavaModelException e) { GWTPluginLog.logError(e); } } return paths; }
Example #2
Source File: StorageDocumentProvider.java From birt with Eclipse Public License 1.0 | 6 votes |
public boolean isReadOnly( Object element ) { IStorage storage = null; try { if ( element instanceof IStorageEditorInput ) { storage = ( (IStorageEditorInput) element ).getStorage( ); } } catch ( CoreException x ) { ExceptionHandler.handle( x ); } if ( storage != null ) { return storage.isReadOnly( ); } return super.isReadOnly( element ); }
Example #3
Source File: DerivedResourceMarkerBasedOpenerContributor.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public boolean collectSourceFileOpeners(IEditorPart editor, IAcceptor<FileOpener> acceptor) { IStorage storage = getStorage(editor); if (storage instanceof IResource) { IResource resource = (IResource) storage; try { Set<URI> uris = Sets.newHashSet(); IMarker[] markers = derivedResourceMarkers.findDerivedResourceMarkers(resource); for (IMarker marker : markers) { String source = derivedResourceMarkers.getSource(marker); if (source != null) uris.add(URI.createURI(source)); } for (URI uri : uris) for (Pair<IStorage, IProject> destination : storage2UriMapper.getStorages(uri)) acceptor.accept(createOpener(destination.getFirst())); return true; } catch (CoreException e) { LOG.error(e.getMessage(), e); } } return false; }
Example #4
Source File: IntegrationTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void testIgnoreFilesInOutputFolder() throws Exception { IJavaProject javaProject = createJavaProjectWithRootSrc("foo"); createFile("foo/src/foo" + F_EXT, "object Foo "); createFile("foo/bar" + F_EXT, "object Bar references Foo"); build(); IProject project = javaProject.getProject(); IResource resourceFromBin = project.findMember(new Path("/bin/foo" + F_EXT)); assertNotNull(resourceFromBin); assertTrue(resourceFromBin instanceof IStorage); assertTrue(resourceFromBin.exists()); URI fakeBinURI = URI.createPlatformResourceURI("/" + project.getName() + "/bin/foo" + F_EXT, true); assertFalse(serviceProvider.canHandle(fakeBinURI, (IStorage) resourceFromBin)); assertTrue(serviceProvider.canHandle(fakeBinURI)); IResource resourceFromRoot = project.findMember(new Path("/bar" + F_EXT)); assertNotNull(resourceFromRoot); assertTrue(resourceFromRoot instanceof IStorage); URI fromRootURI = URI.createPlatformResourceURI("/" + project.getName() + "/bar" + F_EXT, true); assertFalse(serviceProvider.canHandle(fromRootURI, (IStorage) resourceFromBin)); assertTrue(serviceProvider.canHandle(fromRootURI)); }
Example #5
Source File: NLSHintHelper.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public static IStorage getResourceBundle(IJavaProject javaProject, AccessorClassReference accessorClassReference) throws JavaModelException { String resourceBundle= accessorClassReference.getResourceBundleName(); if (resourceBundle == null) return null; String resourceName= Signature.getSimpleName(resourceBundle) + NLSRefactoring.PROPERTY_FILE_EXT; String packName= Signature.getQualifier(resourceBundle); ITypeBinding accessorClass= accessorClassReference.getBinding(); if (accessorClass.isFromSource()) return getResourceBundle(javaProject, packName, resourceName); else if (accessorClass.getJavaElement() != null) return getResourceBundle((IPackageFragmentRoot)accessorClass.getJavaElement().getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT), packName, resourceName); return null; }
Example #6
Source File: JavaSearchHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected void accept(IReferenceDescription referenceDescription) { URI sourceResourceURI = referenceDescription.getSourceEObjectUri().trimFragment(); Iterable<Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(sourceResourceURI); Iterator<Pair<IStorage, IProject>> iterator = storages.iterator(); while (iterator.hasNext()) { Pair<IStorage, IProject> pair = iterator.next(); IStorage storage = pair.getFirst(); IProject project = pair.getSecond(); if (project != null && !project.isHidden()) { ResourceSet resourceSet = getResourceSet(project); EObject sourceEObject = resourceSet.getEObject(referenceDescription.getSourceEObjectUri(), true); if (sourceEObject != null) { ITextRegion region = getLocation( sourceEObject, referenceDescription.getEReference(), referenceDescription.getIndexInList()); acceptMatch(storage, region); } else { acceptMatch(referenceDescription, null); } } } }
Example #7
Source File: AbstractUtilTest.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * 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); }
Example #8
Source File: QueuedBuildData.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
public void queueURI(URI uri) { Iterable<Pair<IStorage, IProject>> iterable = mapper.getStorages(uri); boolean associatedWithProject = false; for (Pair<IStorage, IProject> pair : iterable) { IProject project = pair.getSecond(); if (XtextProjectHelper.hasNature(project) && XtextProjectHelper.hasBuilder(project)) { String projectName = project.getName(); LinkedHashSetQueue<URI> list = projectNameToChangedResource.get(projectName); if (list == null) { list = new LinkedHashSetQueue<>(); projectNameToChangedResource.put(projectName, list); } list.add(uri); associatedWithProject = true; } } if (!associatedWithProject) { this.uris.add(uri); } }
Example #9
Source File: BuilderParticipant.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * @since 2.7 */ protected String getCurrentSourceFolder(IBuildContext context, Delta delta) { Iterable<org.eclipse.xtext.util.Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(delta.getUri()); for (org.eclipse.xtext.util.Pair<IStorage, IProject> pair : storages) { if (pair.getFirst() instanceof IResource) { final IResource resource = (IResource) pair.getFirst(); IProject project = pair.getSecond(); for (OutputConfiguration output : getOutputConfigurations(context).values()) { for (SourceMapping sourceMapping : output.getSourceMappings()) { IContainer folder = ResourceUtil.getContainer(project, sourceMapping.getSourceFolder()); if (folder.contains(resource)) { return sourceMapping.getSourceFolder(); } } } } } return null; }
Example #10
Source File: XtextBuilder.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * Creates a visitor that is used to traverse the information that is obtained from {@link #getDelta(IProject)}. It * accumulates its findings in the given <code>toBeBuilt</code>. */ protected IResourceDeltaVisitor createDeltaVisitor(ToBeBuiltComputer toBeBuiltComputer, ToBeBuilt toBeBuilt, final SubMonitor progress) { IResourceDeltaVisitor visitor = new IResourceDeltaVisitor() { @Override public boolean visit(IResourceDelta delta) throws CoreException { if (progress.isCanceled()) throw new OperationCanceledException(); if (delta.getResource() instanceof IProject) { return true; } if (delta.getResource() instanceof IStorage) { if (delta.getKind() == IResourceDelta.REMOVED) { return toBeBuiltComputer.removeStorage(null, toBeBuilt, (IStorage) delta.getResource()); } else if (delta.getKind() == IResourceDelta.ADDED || delta.getKind() == IResourceDelta.CHANGED) { return toBeBuiltComputer.updateStorage(null, toBeBuilt, (IStorage) delta.getResource()); } } return true; } }; return visitor; }
Example #11
Source File: Storage2UriMapperImpl.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * @since 2.4 */ @Override public Map<URI, IStorage> getAllEntries(IContainer container) { final Map<URI,IStorage> result = newLinkedHashMap(); try { container.accept(new IResourceVisitor() { @Override 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; }
Example #12
Source File: UriValidator.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * @return whether there's possibly an {@link IResourceServiceProvider} for the given storage * @since 2.4 */ public boolean isPossiblyManaged(IStorage storage) { if (!registry.getContentTypeToFactoryMap().isEmpty()) return true; String name = storage.getName(); if (name == null) { return true; } name = URI.encodeSegment(name, true); int index = name.lastIndexOf('.'); if (index == -1) { return true; } return registry.getExtensionToFactoryMap().containsKey(name.substring(index + 1)); }
Example #13
Source File: JavaElementLabelProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public Image getImage(Object element) { Image result= fImageLabelProvider.getImageLabel(element, fImageFlags); if (result != null) { return result; } if (element instanceof IStorage) return fStorageLabelProvider.getImage(element); return result; }
Example #14
Source File: N4JSStorage2UriMapper.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * GH-1190: disable a new behavior of Xtext, which adds pairs <code>FileStoreStorage -> null</code> for file URIs * (see private method <code>#getStorages(URI, IFile)</code> of super class), because these pairs will lead to a * NullPointerException in Xtext's {@code ToBeBuiltComputer#doRemoveProject(IProject, IProgressMonitor)} when * applied to a project located in the external library workspace. */ @Override public Iterable<Pair<IStorage, IProject>> getStorages(URI uri) { Iterable<Pair<IStorage, IProject>> storages = super.getStorages(uri); if (!uri.isPlatformResource() && uri.isFile()) { storages = super.getContribution().getStorages(uri); } else { storages = super.getStorages(uri); } return Iterables.filter(storages, pair -> !(pair != null && pair.getFirst() instanceof FileStoreStorage)); }
Example #15
Source File: XbaseBreakpointUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public SourceRelativeURI getBreakpointURI(IEditorInput input) { IResource resource = Adapters.adapt(input, IResource.class); if (resource != null) return null; if (input instanceof IStorageEditorInput) { IStorage storage; try { storage = ((IStorageEditorInput) input).getStorage(); if (storage instanceof IResource) return null; if (storage instanceof IJarEntryResource) { IJarEntryResource jarEntryResource = (IJarEntryResource) storage; if (!jarEntryResource.getPackageFragmentRoot().isArchive()) return null; Object parent = jarEntryResource.getParent(); if (parent instanceof IPackageFragment) { String path = ((IPackageFragment) parent).getElementName().replace('.', '/'); return new SourceRelativeURI(path + "/" + storage.getName()); } else if (parent instanceof IPackageFragmentRoot) { return new SourceRelativeURI(storage.getName()); } } } catch (CoreException e) { logger.error("Error finding breakpoint URI", e); return null; } } else { IClassFile classFile = Adapters.adapt(input, IClassFile.class); if (classFile != null) { ITrace traceToSource = traceForTypeRootProvider.getTraceToSource(classFile); if (traceToSource == null) return null; for (ILocationInResource loc : traceToSource.getAllAssociatedLocations()) return loc.getSrcRelativeResourceURI(); return null; } } return null; }
Example #16
Source File: TraceForStorageProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public IEclipseTrace getTraceToSource(IStorage derivedResource) { if (derivedResource instanceof IFile) { return getTraceToSource((IFile) derivedResource); } return null; }
Example #17
Source File: Storage2UriMapperImpl.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private URI internalGetUri(/* @NonNull */ IStorage storage) { if (storage instanceof IFile) { return URI.createPlatformResourceURI(storage.getFullPath().toString(), true); } else if (storage instanceof FileStoreStorage) { return URI.createFileURI(((FileStoreStorage) storage).getFullPath().makeAbsolute().toOSString()); } return contribution.getUri(storage); }
Example #18
Source File: N4JSExternalLibraryStorage2UriMapperContribution.java From n4js with Eclipse Public License 1.0 | 5 votes |
@Override public Iterable<Pair<IStorage, IProject>> getStorages(final URI uri) { final IN4JSEclipseProject project = eclipseCore.findProject(uri).orNull(); if (null != project && project.exists()) { final IProject resourceProject = project.getProject(); return singleton(Tuples.create(new URIBasedStorage(uri), resourceProject)); } return emptyList(); }
Example #19
Source File: TraceForTypeRootProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public IEclipseTrace getTraceToSource(final ICompilationUnit javaFile) { IResource resource = null; try { resource = javaFile.getUnderlyingResource(); } catch (JavaModelException e) { resource = getResourceFromNonSrcFolder(javaFile); if(null == resource) { log.error("Error finding trace to source", e); } } if (resource instanceof IStorage) return traceForStorageProvider.getTraceToSource((IStorage) resource); return null; }
Example #20
Source File: ScriptEditorInput.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override public IStorage getStorage() throws CoreException { // TODO Auto-generated method stub return new IStorage() { @Override public Object getAdapter(Class arg0) { return null; } @Override public boolean isReadOnly() { return false; } @Override public String getName() { return ScriptEditorInput.this.getName(); } @Override public IPath getFullPath() { return null; } @Override public InputStream getContents() throws CoreException { return new ByteArrayInputStream(new byte[]{}); } }; }
Example #21
Source File: JvmOutlineNodeElementOpener.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override protected void openEObject(EObject state) { try { if (state instanceof JvmIdentifiableElement && state.eResource() instanceof TypeResource) { IJavaElement javaElement = javaElementFinder.findElementFor((JvmIdentifiableElement) state); if (javaElement instanceof IMember) { IResource resource = javaElement.getResource(); if (resource instanceof IStorage) { ITrace traceToSource = traceInformation.getTraceToSource((IStorage) resource); if (traceToSource != null) { ISourceRange sourceRange = ((IMember) javaElement).getSourceRange(); ILocationInResource sourceInformation = traceToSource.getBestAssociatedLocation(new TextRegion(sourceRange.getOffset(), sourceRange.getLength())); if (sourceInformation != null) { globalURIEditorOpener.open(sourceInformation.getAbsoluteResourceURI().getURI(), javaElement, true); return; } } } globalURIEditorOpener.open(null, javaElement, true); return; } } } catch (Exception exc) { LOG.error("Error opening java editor", exc); } super.openEObject(state); }
Example #22
Source File: WorkbenchResolutionAdaptorRunTest.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
private void mockMarkerResource(final URI uri) throws CoreException { // Resource is a file and so gets processed when(mockMarker.getResource()).thenReturn(mockFile); when(mockFile.getName()).thenReturn(uri.lastSegment()); when(mockFile.findMarkers(anyString(), anyBoolean(), anyInt())).thenReturn(new IMarker[] {}); when(mockMarker.getAttribute(eq(Issue.URI_KEY), anyString())).thenReturn(uri.toString()); when(mockMarker.isSubtypeOf(eq(MarkerTypes.ANY_VALIDATION))).thenReturn(true); when(mockStorage2UriMapper.getUri(eq(mockFile))).thenReturn(uri); @SuppressWarnings("unchecked") Iterable<Pair<IStorage, IProject>> storages = Lists.newArrayList(Tuples.create((IStorage) mockFile, mock(IProject.class))); when(mockStorage2UriMapper.getStorages(eq(uri))).thenReturn(storages); when(mockLanguageResourceHelper.isLanguageResource(eq(mockFile))).thenReturn(true); }
Example #23
Source File: StorageEditorInput.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
@SuppressWarnings("rawtypes") @Override public Object getAdapter(Class adapter) { Object adapted = super.getAdapter(adapter); if (adapted == null) { if (IStorage.class.equals(adapter)) { return fStorage; } } return adapted; }
Example #24
Source File: TraceForStorageProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public boolean isTraceFile(IStorage storage) { if (!(storage instanceof IFile)) { return false; } IFile file = (IFile) storage; String originLastSegment = file.getFullPath().lastSegment(); return getTraceFileNameProvider().isTraceFileName(originLastSegment); }
Example #25
Source File: WorkingCopyOwnerProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * @deprecated This method is not used anymore. It is not necessary that a resource, that contains derived jvm types, is on the project's classpath. * @since 2.9 */ @Deprecated protected boolean isOnClassPath(IJavaProject javaProject, IStorage storage) { if (storage instanceof IJarEntryResource) { javaProject.isOnClasspath(((IJarEntryResource) storage).getPackageFragmentRoot()); } if (storage instanceof IResource) { return javaProject.isOnClasspath((IResource)storage); } return false; }
Example #26
Source File: AbstractAllContainersState.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.3 */ protected boolean isAffectingContainerState(IResourceDelta delta) { if (delta.getKind() == IResourceDelta.ADDED || delta.getKind() == IResourceDelta.REMOVED) { if (delta.getResource() instanceof IStorage) { if (getUri((IStorage) delta.getResource()) != null) { return true; } } } else if (delta.getKind() == IResourceDelta.CHANGED && delta.getResource() instanceof IProject) { if ((delta.getFlags() & IResourceDelta.DESCRIPTION) != 0) { return true; } } return false; }
Example #27
Source File: NLSHintHelper.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static IStorage getResourceBundle(ICompilationUnit compilationUnit) throws JavaModelException { IJavaProject project= compilationUnit.getJavaProject(); if (project == null) return null; String name= getResourceBundleName(compilationUnit); if (name == null) return null; String packName= Signature.getQualifier(name); String resourceName= Signature.getSimpleName(name) + NLSRefactoring.PROPERTY_FILE_EXT; return getResourceBundle(project, packName, resourceName); }
Example #28
Source File: CheckEclipseGeneratorConfigProvider.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
@Override public CheckGeneratorConfig get(final URI uri) { CheckGeneratorConfig result = new CheckGeneratorConfig(); IProject project = null; if (uri != null) { Pair<IStorage, IProject> pair = Iterables.getFirst(storage2UriMapper.getStorages(uri), null); if (pair != null) { project = pair.getSecond(); } } xbaseBuilderPreferenceAccess.loadBuilderPreferences(result, project); return result; }
Example #29
Source File: SARLNatureAddingEditorCallback.java From sarl with Apache License 2.0 | 5 votes |
private boolean canBuild(XtextEditor editor) { final IResource resource = editor.getResource(); if (!(resource instanceof IStorage)) { return false; } final IStorage storage = (IStorage) resource; final URI uri = this.mapper.getUri(storage); return this.uriValidator.canBuild(uri, storage); }
Example #30
Source File: JavaClassPathResourceForIEditorInputFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override protected ResourceSet getResourceSet(/* @Nullable */ IStorage storage) { if (storage instanceof IJarEntryResource) { IPackageFragmentRoot root = ((IJarEntryResource) storage).getPackageFragmentRoot(); if (root != null) { IJavaProject project = root.getJavaProject(); if (project != null) return getResourceSetProvider().get(project.getProject()); } } return super.getResourceSet(storage); }