Java Code Examples for org.eclipse.core.resources.IResource#isPhantom()

The following examples show how to use org.eclipse.core.resources.IResource#isPhantom() . 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: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected RefactoringStatus verifyDestination(IResource resource) throws JavaModelException {
	Assert.isNotNull(resource);
	if (!resource.exists() || resource.isPhantom()) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_phantom);
	}
	if (!resource.isAccessible()) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_inaccessible);
	}

	if (resource.getType() == IResource.ROOT) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);
	}

	if (isChildOfOrEqualToAnyFolder(resource)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);
	}

	if (containsLinkedResources() && !ReorgUtils.canBeDestinationForLinkedResources(resource)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_linked);
	}

	return new RefactoringStatus();
}
 
Example 2
Source File: DeleteResourceAndCloseEditorAction.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns whether delete can be performed on the current selection.
 * @param resources
 *            the selected resources
 * @return <code>true</code> if the resources can be deleted, and <code>false</code> if the selection contains
 *         non-resources or phantom resources
 */
private boolean canDelete(IResource[] resources) {
	// allow only projects or only non-projects to be selected;
	// note that the selection may contain multiple types of resource
	if (!(containsOnlyProjects(resources) || containsOnlyNonProjects(resources))) {
		return false;
	}

	if (resources.length == 0) {
		return false;
	}
	// Return true if everything in the selection exists.
	for (int i = 0; i < resources.length; i++) {
		IResource resource = resources[i];
		if (resource.isPhantom()) {
			return false;
		}
	}
	return true;
}
 
Example 3
Source File: DeleteResourceAndCloseEditorAction.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns whether delete can be performed on the current selection.
 * @param resources
 *            the selected resources
 * @return <code>true</code> if the resources can be deleted, and <code>false</code> if the selection contains
 *         non-resources or phantom resources
 */
private boolean canDelete(IResource[] resources) {
	// allow only projects or only non-projects to be selected;
	// note that the selection may contain multiple types of resource
	if (!(containsOnlyProjects(resources) || containsOnlyNonProjects(resources))) {
		return false;
	}

	if (resources.length == 0) {
		return false;
	}
	// Return true if everything in the selection exists.
	for (int i = 0; i < resources.length; i++) {
		IResource resource = resources[i];
		if (resource.isPhantom()) {
			return false;
		}
	}
	return true;
}
 
Example 4
Source File: ReorgPolicyFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean canEnable() throws JavaModelException {
	IResource[] resources= getResources();
	for (int i= 0; i < resources.length; i++) {
		IResource resource= resources[i];
		if (!resource.exists() || resource.isPhantom() || !resource.isAccessible())
			return false;
	}

	IJavaElement[] javaElements= getJavaElements();
	for (int i= 0; i < javaElements.length; i++) {
		IJavaElement element= javaElements[i];
		if (!element.exists())
			return false;
	}
	return resources.length > 0 || javaElements.length > 0;
}
 
Example 5
Source File: ReorgPolicyFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected RefactoringStatus verifyDestination(IResource resource) {
	Assert.isNotNull(resource);
	if (!resource.exists() || resource.isPhantom())
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_phantom);
	if (!resource.isAccessible())
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_inaccessible);

	if (!(resource instanceof IContainer))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);

	if (resource.getType() == IResource.ROOT)
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);

	if (isChildOfOrEqualToAnyFolder(resource))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);

	if (containsLinkedResources() && !ReorgUtils.canBeDestinationForLinkedResources(resource))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_linked);

	return new RefactoringStatus();
}
 
Example 6
Source File: ReorgPolicyFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected RefactoringStatus verifyDestination(IResource resource) {
	Assert.isNotNull(resource);
	if (!resource.exists() || resource.isPhantom())
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_phantom);
	if (!resource.isAccessible())
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_inaccessible);

	if (!(resource instanceof IContainer))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);

	if (resource.getType() == IResource.ROOT)
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);

	if (isChildOfOrEqualToAnyFolder(resource))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);

	if (containsLinkedResources() && !ReorgUtils.canBeDestinationForLinkedResources(resource))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_linked);

	return new RefactoringStatus();
}
 
Example 7
Source File: ReorgPolicyFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected RefactoringStatus verifyDestination(IResource resource) throws JavaModelException {
	Assert.isNotNull(resource);
	if (!resource.exists() || resource.isPhantom())
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_phantom);
	if (!resource.isAccessible())
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_inaccessible);

	if (resource.getType() == IResource.ROOT)
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);

	if (isChildOfOrEqualToAnyFolder(resource))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);

	if (containsLinkedResources() && !ReorgUtils.canBeDestinationForLinkedResources(resource))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_linked);

	return new RefactoringStatus();
}
 
Example 8
Source File: StatusCacheManager.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * get the status of the given resource
 * @throws SVNException
 */
private LocalResourceStatus getStatus(IResource resource, StatusUpdateStrategy strategy, boolean getStatusFromSvn) throws SVNException {
	if (!resource.exists() && !resource.isPhantom())
	{
		return null;
	}
    LocalResourceStatus status = null;        
    status = statusCache.getStatus(resource);
    
    // we get it using svn 
    if (status == null && getStatusFromSvn)
    {
    	status = basicGetStatus(resource, strategy);
    }
    return status;
}
 
Example 9
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean canEnable() throws JavaModelException {
	IResource[] resources= getResources();
	for (int i= 0; i < resources.length; i++) {
		IResource resource= resources[i];
		if (!resource.exists() || resource.isPhantom() || !resource.isAccessible()) {
			return false;
		}
	}

	IJavaElement[] javaElements= getJavaElements();
	for (int i= 0; i < javaElements.length; i++) {
		IJavaElement element= javaElements[i];
		if (!element.exists()) {
			return false;
		}
	}
	return resources.length > 0 || javaElements.length > 0;
}
 
Example 10
Source File: StatusCacheManager.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
* Refresh the status of the given resource to the give depth. The depth can
* be deeper in case of phantom resources. These have to be traversed to
* infinite always ...
* 
* @param resource
* @param recursive
* @return array of resources which were refreshed (including all phantoms
*         and their children)
* @throws SVNException
*/
  public IResource[] refreshStatus(final IResource resource, final boolean recursive) throws SVNException {
  	if (SVNWorkspaceRoot.isLinkedResource(resource)) { return new IResource[0]; }

final int depth = (recursive) ? IResource.DEPTH_INFINITE : IResource.DEPTH_ONE;

  	final StatusUpdateStrategy strategy = 
  		(depth == IResource.DEPTH_INFINITE) 
					? (StatusUpdateStrategy) new RecursiveStatusUpdateStrategy(statusCache)
					: (StatusUpdateStrategy) new NonRecursiveStatusUpdateStrategy(statusCache);
try {
	List<IResource> refreshedResources = updateCache(resource, strategy.statusesToUpdate(resource));
	Set<IResource> resourcesToRefresh = resourcesToRefresh(resource, depth, IContainer.INCLUDE_PHANTOMS, refreshedResources.size());
	for (Iterator<IResource> iter = refreshedResources.iterator(); iter.hasNext();) {
		resourcesToRefresh.remove(iter.next());
	}
	//Resources which were not refreshed above (e.g. deleted resources)
	//We do it with depth = infinite, so the whole deleted trees are refreshed.
	for (IResource res : resourcesToRefresh) {
		if ((res.getType() != IResource.FILE) && res.isPhantom())
		{
			Set<IResource> children = resourcesToRefresh(res, IResource.DEPTH_INFINITE, IContainer.INCLUDE_PHANTOMS | IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS, 0);
			for (IResource child : children) {
				statusCache.removeStatus(child);
				refreshedResources.add(child);
			}
		}
		statusCache.removeStatus(res);
		refreshedResources.add(res);
	}
	return (IResource[]) refreshedResources.toArray(new IResource[refreshedResources.size()]);
}
catch (CoreException e)
{
	throw SVNException.wrapException(e);
}
  }
 
Example 11
Source File: StatusCacheManager.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private Set<IResource> resourcesToRefresh(IResource resource, int depth, int flags, int expectedSize) throws CoreException
  {
      if (!resource.exists() && !resource.isPhantom())
      {
          return new HashSet<IResource>(0);
      }
  	final Set<IResource> resultSet = (expectedSize != 0) ? new HashSet<IResource>(expectedSize) : new HashSet<IResource>();
resource.accept(new IResourceVisitor() {
	public boolean visit(IResource aResource) throws CoreException {
		resultSet.add(aResource);
		return true;
	}
}, depth, flags);
return resultSet;
  }
 
Example 12
Source File: SynchronizerSyncInfoCache.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public IResource addStatus(IResource resource, LocalResourceStatus status) {
	try {
		if (resource == null) return null;
		if (status.isUnversioned() && !(resource.exists() || resource.isPhantom()))
		{
			return resource;
		}
		setCachedSyncBytes(resource, status.getBytes());
		return resource;
	} catch (SVNException e) {
	    if (!"".equals(e.getMessage())) // We send these exceptions so that the log does not go nuts
	        SVNProviderPlugin.log(e);
		return null;
	}
}
 
Example 13
Source File: RefactoringAvailabilityTester.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isDeleteAvailable(final IResource resource) {
	if (!resource.exists() || resource.isPhantom())
		return false;
	if (resource.getType() == IResource.ROOT || resource.getType() == IResource.PROJECT)
		return false;
	return true;
}
 
Example 14
Source File: DeleteResourceAction.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns whether delete can be performed on the current selection.
 *
 * @param resources
 *            the selected resources
 * @return <code>true</code> if the resources can be deleted, and <code>false</code> if the selection contains
 *         non-resources or phantom resources
 */
private boolean canDelete(final List<? extends IResource> resources) {
	// allow only projects or only non-projects to be selected;
	// note that the selection may contain multiple types of resource
	if (!(containsOnlyProjects(resources) || containsOnlyNonProjects(resources))) { return false; }

	if (resources.isEmpty()) { return false; }
	// Return true if everything in the selection exists.
	for (int i = 0; i < resources.size(); i++) {
		final IResource resource = resources.get(i);
		if (resource.isPhantom()) { return false; }
	}
	return true;
}
 
Example 15
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected RefactoringStatus verifyDestination(IResource resource) {
	Assert.isNotNull(resource);
	if (!resource.exists() || resource.isPhantom()) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_phantom);
	}
	if (!resource.isAccessible()) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_inaccessible);
	}

	if (!(resource instanceof IContainer)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);
	}

	if (resource.getType() == IResource.ROOT) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);
	}

	if (isChildOfOrEqualToAnyFolder(resource)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);
	}

	if (containsLinkedResources() && !ReorgUtils.canBeDestinationForLinkedResources(resource)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_linked);
	}

	return new RefactoringStatus();
}
 
Example 16
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected RefactoringStatus verifyDestination(IResource resource) {
	Assert.isNotNull(resource);
	if (!resource.exists() || resource.isPhantom()) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_phantom);
	}
	if (!resource.isAccessible()) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_inaccessible);
	}

	if (!(resource instanceof IContainer)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);
	}

	if (resource.getType() == IResource.ROOT) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);
	}

	if (isChildOfOrEqualToAnyFolder(resource)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);
	}

	if (containsLinkedResources() && !ReorgUtils.canBeDestinationForLinkedResources(resource)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_linked);
	}

	return new RefactoringStatus();
}
 
Example 17
Source File: RefactoringAvailabilityTester.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static boolean isDeleteAvailable(final IResource resource) {
	if (!resource.exists() || resource.isPhantom()) {
		return false;
	}
	if (resource.getType() == IResource.ROOT || resource.getType() == IResource.PROJECT) {
		return false;
	}
	return true;
}
 
Example 18
Source File: SelectModulaSourceFileDialog.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean isConsistentItem(Object item) {
    ListItem li = (ListItem)item;
    IResource resource = li.getResource();
    return resource==null || !resource.isPhantom();
}
 
Example 19
Source File: ToStringResourceDeltaVisitor.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean visit(IResourceDelta delta) throws CoreException {
  boolean result = true;
  switch (delta.getKind()) {
    case IResourceDelta.NO_CHANGE:
      sb.append("0");
      result = false;
      break;
    case IResourceDelta.CHANGED:
      sb.append("C(");
      int f = delta.getFlags();
      if (f == 0) {
        sb.append("0) ");
      } else {
        Set<Entry<Integer, String>> entrySet = map.entrySet();
        for (Entry<Integer, String> entry : entrySet) {
          if (0 != (f & entry.getKey())) sb.append(entry.getValue());
        }
        sb.append(") ");
      }

      break;
    case IResourceDelta.ADDED:
      sb.append("A ");
      break;
    case IResourceDelta.REMOVED:
      sb.append("R ");
      break;
    default:
      sb.append("? ");
  }
  IResource resource = delta.getResource();
  if (resource != null) {
    if (resource.isDerived()) sb.append("* ");

    if (resource.isPhantom()) sb.append("P ");

    if (resource.isHidden()) sb.append("H ");

    sb.append(resource.getFullPath().toPortableString());
  } else {
    sb.append("No resource");
  }
  sb.append("\n");

  return result;
}
 
Example 20
Source File: AbstractSarlScriptInteractiveSelector.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Replies if the given resource could be considered for discovering an agent to be launched.
 *
 * @param resource the resource.
 * @return {@code true} if the resource could be explored.
 */
@SuppressWarnings("static-method")
protected boolean isValidResource(IResource resource) {
	return resource.isAccessible() && !resource.isHidden() && !resource.isPhantom() && !resource.isDerived();
}