Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2009 itemis AG (http://www.itemis.eu) and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html /
  
  package org.eclipse.xtext.ui.resource;
  
 import static com.google.common.collect.Maps.*;
 
 import java.util.Map;
 
 import  org.eclipse.core.resources.IContainer;
 import  org.eclipse.core.resources.IFile;
 import  org.eclipse.core.resources.IFolder;
 import  org.eclipse.core.resources.IProject;
 import  org.eclipse.core.resources.IResource;
 import  org.eclipse.core.resources.IResourceVisitor;
 import  org.eclipse.core.resources.IStorage;
 import  org.eclipse.core.resources.IWorkspaceRoot;
 import  org.eclipse.core.resources.ResourcesPlugin;
 import  org.eclipse.core.runtime.CoreException;
 import  org.eclipse.core.runtime.IPath;
 import  org.eclipse.core.runtime.Path;
 

Author(s):
Sven Efftinge - Initial contribution and API
Noextend:
This class is not intended to be subclassed by clients.
 
 public class Storage2UriMapperImpl implements IStorage2UriMapperExtension {
 	
 	private final static Logger log = Logger.getLogger(Storage2UriMapperImpl.class);
 	
 
 		public void initializeCache() {
 			// nothing to do
 		}
 		public boolean isRejected(/* @NonNull */ IFolder folder) {
 			return false;
 		}
 		/* @NonNull */ 
 		public Iterable<Pair<IStorage, IProject>> getStorages(/* @NonNull */ URI uri) {
 			return Collections.emptyList();
 		}
 		public URI getUri(/* @NonNull */ IStorage storage) {
 			return null;
 		}
 	};

Since:
2.4
 
 	public final void setUriValidator(UriValidator uriValidator) {
 		this. = uriValidator;
 	}

Public for testing purpose

Since:
2.5
Nooverride:
This method is not intended to be re-implemented or extended by clients.
Noreference:
This method is not intended to be referenced by clients.
 
 	public void setContribution(IStorage2UriMapperContribution contribution) {
 		this. = contribution;
 	}

Public for testing purpose

Since:
2.5
Nooverride:
This method is not intended to be re-implemented or extended by clients.
Noreference:
This method is not intended to be referenced by clients.
 
 		return ;
 	}
 	
		final int size = allContributions.size();
		switch(size) {
			case 0: 
				// nothing to do
				break;
			case 1:
				 = allContributions.get(0);
				break;
			default:
					public void initializeCache() {
						for(IStorage2UriMapperContribution contributionallContributions) {
							contribution.initializeCache();
						}
					}
					public boolean isRejected(/* @NonNull */ IFolder folder) {
						for(int i = 0; i < sizei++) {
							if (allContributions.get(i).isRejected(folder)) {
								return true;
							}
						}
						return false;
					}
					/* @NonNull */
					public Iterable<Pair<IStorage, IProject>> getStorages(/* @NonNull */ final URI uri) {
						return Iterables.concat(Lists.transform(allContributionsnew Function<IStorage2UriMapperContributionIterable<Pair<IStorage, IProject>>>() {
							/* @NonNull */
							public Iterable<Pair<IStorage, IProject>> apply(IStorage2UriMapperContribution contribution) {
								return contribution.getStorages(uri);
							}
						}));
					}
					/* @Nullable */
					public URI getUri(/* @NonNull */ IStorage storage) {
						for(int i = 0; i < sizei++) {
							URI result = allContributions.get(i).getUri(storage);
							if (result != null) {
								return result;
							}
						}
						return null;
					}
				};
		}
	}

Since:
2.5
	public void initializeCache() {
	}

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 resourcethrows CoreException {
					if (resource instanceof IFile) {
						final IFile storage = (IFile) resource;
						URI uri = getUri(storage);
						if (uri != null)
							result.put(uristorage);
					}
					if (resource instanceof IFolder) {
						return isHandled((IFolder)resource);
					}
					return true;
				}
			});
catch (CoreException e) {
			.error(e.getMessage(), e);
		}
		return result;
	}

Return true if the folder should be traversed. False otherwise. Defaults to true for all folders.

Returns:
true if the folder should be traversed. False otherwise.
Since:
2.4
	protected boolean isHandled(IFolder folder) {
		return !.isRejected(folder);
	}
	public Iterable<Pair<IStorage, IProject>> getStorages(URI uri) {
		if (!uri.isPlatformResource()) {
			// support storage lookup by absolute file URI as it is possibly resolved by importURI references
			if (uri.isFile()) {
				IPath path = new Path(uri.toFileString());
				if (path.isAbsolute()) {
					IFile file = getWorkspaceRoot().getFileForLocation(path);
					return getStorages(urifile);
				}
			}
		}
		IFile file = getWorkspaceRoot().getFile(new Path(uri.toPlatformString(true)));
		return getStorages(urifile);
	}
	private Iterable<Pair<IStorage, IProject>> getStorages(/* @NonNull */ URI uri, IFile file) {
		if (file == null || !file.isAccessible()) {
		}
		return Collections.singleton(Tuples.<IStorage,IProject>create(filefile.getProject()));
	}
	protected IWorkspaceRoot getWorkspaceRoot() {
		return ResourcesPlugin.getWorkspace().getRoot();
	}
	public URI getUri(IStorage storage) {
			return null;
		URI uri = internalGetUri(storage);
		if (uri != null && isValidUri(uri,storage))
			return uri;
		return null;
	}
	private URI internalGetUri(/* @NonNull */ IStorage storage) {
		if (storage instanceof IFile) {
			return URI.createPlatformResourceURI(storage.getFullPath().toString(), true);
		return .getUri(storage);
	}
	public boolean isValidUri(URI uri, IStorage storage) {
		boolean valid = .isValid(uristorage);
		return valid;
	}
New to GrepCode? Check out our FAQ X