use of org.eclipse.emf.common.util.URI in project xtext-xtend by eclipse.
the class XtendFileRenameParticipant method createRenameElementContexts.
@Override
protected List<? extends IRenameElementContext> createRenameElementContexts(Object element) {
if (super.getNewName().endsWith(".xtend")) {
IFile file = (IFile) element;
final IPath filePath = file.getFullPath();
final IPath newPath = file.getFullPath().removeLastSegments(1).append(getNewName() + ".xtend");
String className = trimFileExtension(file.getName());
if (className != null) {
ResourceSet resourceSet = resourceSetProvider.get(file.getProject());
URI resourceURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
Resource resource = resourceSet.getResource(resourceURI, true);
if (resource != null && !resource.getContents().isEmpty()) {
for (XtendTypeDeclaration type : EcoreUtil2.eAllOfType(resource.getContents().get(0), XtendTypeDeclaration.class)) {
if (equal(className, type.getName())) {
IRenameElementContext renameElementContext = renameContextFactory.createRenameElementContext(type, null, null, (XtextResource) resource);
if (renameElementContext instanceof IChangeRedirector.Aware)
((IChangeRedirector.Aware) renameElementContext).setChangeRedirector(new IChangeRedirector() {
@Override
public IPath getRedirectedPath(IPath source) {
return source.equals(filePath) ? newPath : source;
}
});
return singletonList(renameElementContext);
}
}
}
}
}
return super.createRenameElementContexts(element);
}
use of org.eclipse.emf.common.util.URI in project xtext-xtend by eclipse.
the class XtendUIValidator method getExpectedPackageName.
protected String getExpectedPackageName(XtendFile xtendFile) {
URI fileURI = xtendFile.eResource().getURI();
for (Pair<IStorage, IProject> storage : storage2UriMapper.getStorages(fileURI)) {
if (storage.getFirst() instanceof IFile) {
IPath fileWorkspacePath = storage.getFirst().getFullPath();
IJavaProject javaProject = JavaCore.create(storage.getSecond());
if (javaProject != null && javaProject.exists() && javaProject.isOpen()) {
try {
for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) {
if (!root.isArchive() && !root.isExternal()) {
IResource resource = root.getResource();
if (resource != null) {
IPath sourceFolderPath = resource.getFullPath();
if (sourceFolderPath.isPrefixOf(fileWorkspacePath)) {
IPath claspathRelativePath = fileWorkspacePath.makeRelativeTo(sourceFolderPath);
return claspathRelativePath.removeLastSegments(1).toString().replace("/", ".");
}
}
}
}
} catch (JavaModelException e) {
LOG.error("Error resolving expected path for XtendFile", e);
}
}
}
}
return null;
}
use of org.eclipse.emf.common.util.URI in project xtext-xtend by eclipse.
the class UIResourceChangeRegistry method readState.
public void readState(final InputStream in) {
try {
final DataInputStream reader = new DataInputStream(in);
for (final HashMultimap<String, URI> map : Collections.<HashMultimap<String, URI>>unmodifiableList(CollectionLiterals.<HashMultimap<String, URI>>newArrayList(this.existsListeners, this.charsetListeners, this.childrenListeners, this.contentsListeners))) {
{
final int urisForExists = reader.readInt();
for (int i = 0; (i < urisForExists); i++) {
{
final String path = reader.readUTF();
final String uri = reader.readUTF();
map.put(path, URI.createURI(uri));
}
}
}
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.emf.common.util.URI in project xtext-xtend by eclipse.
the class XtendUIResourceDescriptionManager method isAffected.
@Override
public boolean isAffected(Collection<Delta> deltas, IResourceDescription candidate, IResourceDescriptions context) {
// skip collecting the outgoing references since we don't index references anyway
// Set<URI> outgoingReferences = getDescriptionUtils().collectOutgoingReferences(candidate);
// if (!outgoingReferences.isEmpty()) {
// for (IResourceDescription.Delta delta : deltas)
// if (hasChanges(delta, candidate) && outgoingReferences.contains(delta.getUri()))
// return true;
// }
// this is a tradeoff - we could either check whether a given delta uri is contained
// in a reachable container and check for intersecting names afterwards, or we can do
// the other way round
// unfortunately there is no way to decide reliably which algorithm scales better
// note that this method is called for each description so we have something like a
// number of deltas x number of resources which is not really nice
List<IContainer> containers = null;
Collection<QualifiedName> importedNames = getImportedNames(candidate);
Map<String, Boolean> checkedProjects = Maps.newHashMap();
for (IResourceDescription.Delta delta : deltas) {
if (hasChanges(delta, candidate)) {
// not a java resource - delta's resource should be contained in a visible container
// as long as we did not delete the resource
URI uri = delta.getUri();
if ((uri.isPlatform() || uri.isArchive()) && delta.getNew() != null) {
if (containers == null)
containers = getContainerManager().getVisibleContainers(candidate, context);
boolean descriptionIsContained = false;
for (int i = 0; i < containers.size() && !descriptionIsContained; i++) {
descriptionIsContained = containers.get(i).hasResourceDescription(uri);
}
if (!descriptionIsContained && !isProjectDependency(uri, candidate.getURI(), checkedProjects)) {
return false;
}
}
if (isAffected(importedNames, delta.getNew()) || isAffected(importedNames, delta.getOld())) {
return true;
}
}
}
return false;
}
use of org.eclipse.emf.common.util.URI in project xtext-xtend by eclipse.
the class UIResourceChangeRegistryTest method testConcurrentDiscard.
@Test
public void testConcurrentDiscard() throws Exception {
try {
final Consumer<Integer> _function = (Integer it) -> {
this.resourceChangeRegistry.registerCreateOrModify("/foo", this.uri.appendSegment(it.toString()));
};
new IntegerRange(1, 10000).forEach(_function);
final Runnable _function_1 = () -> {
final SecureRandom random = new SecureRandom(new byte[] { ((byte) 1) });
final Consumer<Integer> _function_2 = (Integer it) -> {
final URI removedURI = this.uri.appendSegment(Integer.valueOf(random.nextInt(10000)).toString());
this.resourceChangeRegistry.discardCreateOrModifyInformation(removedURI);
};
new IntegerRange(1, 1000).forEach(_function_2);
};
final Runnable r = _function_1;
final ExecutorService executorService = Executors.newCachedThreadPool();
try {
final Future<?> future1 = executorService.submit(r);
final Future<?> future2 = executorService.submit(r);
final Future<?> future3 = executorService.submit(r);
final Future<?> future4 = executorService.submit(r);
future1.get();
future2.get();
future3.get();
future4.get();
} catch (final Throwable _t) {
if (_t instanceof ExecutionException) {
final ExecutionException e = (ExecutionException) _t;
throw e.getCause();
} else {
throw Exceptions.sneakyThrow(_t);
}
} finally {
executorService.shutdown();
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations