Commit 0799ebb4 authored by Stephan Eberle's avatar Stephan Eberle
Browse files

Made sure that ProjectResourceScope can operate consistently on

in-memory model files by reworking
ProjectResourceScope#belongsToRootOrReferencedProjects(URI, boolean) -
converted provided URI to corresponding IFile and delegated to
ProjectResourceScope#belongsTo(IFile, boolean)} rather
than relying on mappings of physically existing IFiles to URIs provided
by ProjectResourceCache
parent 7c99903a
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
/**
 * <copyright>
 *
 * Copyright (c) {contributing company name} and others.
 * Copyright (c) 2008-2019 BWM Car IT, See4sys, itemis 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
 *
 * Contributors:
 *     {contributing company name} - Initial API and implementation
 *     BMW Car IT - Initial API and implementation
 *
 * </copyright>
 */
@@ -21,6 +21,7 @@ import java.util.Map;
import java.util.Set;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
@@ -37,6 +38,13 @@ import org.eclipse.sphinx.platform.resources.DefaultResourceChangeHandler;
import org.eclipse.sphinx.platform.resources.ResourceDeltaVisitor;
import org.eclipse.sphinx.platform.util.PlatformLogUtil;

/**
 * @deprecated Was used by {@link ProjectResourceScope#belongsToRootOrReferencedProjects(URI, boolean)} before whose
 *             implementation has been greatly simplified by converting provided {@link URI} to corresponding
 *             {@link IFile} and delegating to {@link ProjectResourceScope#belongsTo(IFile, boolean)} rather than
 *             relying on {@link IFile} to {@link URI} mappings provided by this cache.
 */
@Deprecated
public class ProjectResourceCache {

	class InvalidationListener implements IResourceChangeListener {
+5 −17
Original line number Diff line number Diff line
/**
 * <copyright>
 *
 * Copyright (c) 2008-2014 See4sys, itemis, BMW Car IT and others.
 * Copyright (c) 2008-2019 See4sys, itemis, BMW Car IT 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
@@ -29,12 +29,12 @@ import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.sphinx.emf.scoping.ProjectResourceScopeProvider.IReferencedProjectsProvider;
import org.eclipse.sphinx.emf.scoping.ProjectResourceScopeProvider.ReferencedProjectsProvider;
import org.eclipse.sphinx.emf.util.EcorePlatformUtil;
import org.eclipse.sphinx.platform.util.ExtendedPlatform;

public class ProjectResourceScope extends AbstractResourceScope {

	protected IProject rootProject;
	private ProjectResourceCache resourceCache;

	// Use a non-caching provider by default
	protected IReferencedProjectsProvider referencedProjectsProvider = new ReferencedProjectsProvider();
@@ -42,7 +42,6 @@ public class ProjectResourceScope extends AbstractResourceScope {
	public ProjectResourceScope(IResource resource) {
		Assert.isNotNull(resource);
		rootProject = resource.getProject();
		resourceCache = new ProjectResourceCache();
	}

	protected void setReferencedProjectsProvider(IReferencedProjectsProvider referencedProjectsProvider) {
@@ -157,20 +156,9 @@ public class ProjectResourceScope extends AbstractResourceScope {
		return belongsToRootOrReferencedProjects(uri, includeReferencedScopes);
	}

	protected boolean belongsToRootOrReferencedProjects(URI model, boolean includeReferencedScopes) {
		if (model != null) {
			if (resourceCache.getResources(rootProject).contains(model)) {
				return true;
			}
			if (includeReferencedScopes) {
				for (IResource referenced : getReferencedRoots()) {
					if (resourceCache.getResources(referenced.getProject()).contains(model)) {
						return true;
					}
				}
			}
		}
		return false;
	protected boolean belongsToRootOrReferencedProjects(URI uri, boolean includeReferencedScopes) {
		IFile file = EcorePlatformUtil.getFile(uri);
		return belongsTo(file, includeReferencedScopes);
	}

	protected boolean belongsToRootOrReferencedProjects(IFile file, boolean includeReferencedScopes) {