Java Code Examples for org.eclipse.core.resources.IContainer#equals()

The following examples show how to use org.eclipse.core.resources.IContainer#equals() . 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 destination) throws JavaModelException {
	RefactoringStatus superStatus= super.verifyDestination(destination);
	if (superStatus.hasFatalError()) {
		return superStatus;
	}

	Object commonParent= getCommonParent();
	if (destination.equals(commonParent)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	}
	IContainer destinationAsContainer= getDestinationAsContainer();
	if (destinationAsContainer != null && destinationAsContainer.equals(commonParent)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	}
	IJavaElement destinationContainerAsPackage= getDestinationContainerAsJavaElement();
	if (destinationContainerAsPackage != null && destinationContainerAsPackage.equals(commonParent)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	}

	if (cannotUpdateReferencesForDestination()) {
		superStatus.addInfo(RefactoringCoreMessages.ReorgPolicyFactory_noJavaUpdates);
	}

	return superStatus;
}
 
Example 2
Source File: ModuleFile.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns whether a folder is on the public path of this module. The public paths include the
 * paths explicitly declared with <code>&lt;public&gt;</code> tags and all of their descendant
 * sub-folders.
 *
 * @param folder the folder to check
 * @return <code>true</code> if this folder is on a public path, and <code>false</code> otherwise
 */
public boolean isPublicPath(IFolder folder) {
  IFolder[] publicFolders = getFolders(getPublicPaths());

  IContainer moduleContainer = getFile().getParent();
  IContainer container = folder;

  // Walk up the ancestor chain looking for a public path matching this folder
  while (container.getType() == IResource.FOLDER) {
    // If we reach the module's container, we're done searching
    if (container.equals(moduleContainer)) {
      return false;
    }

    for (IFolder publicFolder : publicFolders) {
      if (container.equals(publicFolder)) {
        return true;
      }
    }

    container = container.getParent();
  }

  return false;
}
 
Example 3
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(IJavaElement destination) throws JavaModelException {
	RefactoringStatus superStatus= super.verifyDestination(destination);
	if (superStatus.hasFatalError())
		return superStatus;

	Object commonParent= new ParentChecker(getResources(), getJavaElements()).getCommonParent();
	if (destination.equals(commonParent))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	IContainer destinationAsContainer= getDestinationAsContainer();
	if (destinationAsContainer != null && (destinationAsContainer.equals(commonParent) || commonParent instanceof IPackageFragmentRoot
			&& destinationAsContainer.equals(((IPackageFragmentRoot) commonParent).getResource())))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	IPackageFragment destinationAsPackage= getDestinationAsPackageFragment();
	if (destinationAsPackage != null && (destinationAsPackage.equals(commonParent)))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);

	if (cannotUpdateReferencesForDestination())
		superStatus.addInfo(RefactoringCoreMessages.ReorgPolicyFactory_noJavaUpdates);

	return superStatus;
}
 
Example 4
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 destination) throws JavaModelException {
	RefactoringStatus superStatus= super.verifyDestination(destination);
	if (superStatus.hasFatalError())
		return superStatus;

	Object commonParent= getCommonParent();
	if (destination.equals(commonParent))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	IContainer destinationAsContainer= getDestinationAsContainer();
	if (destinationAsContainer != null && destinationAsContainer.equals(commonParent))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	IJavaElement destinationContainerAsPackage= getDestinationContainerAsJavaElement();
	if (destinationContainerAsPackage != null && destinationContainerAsPackage.equals(commonParent))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	
	if (cannotUpdateReferencesForDestination())
		superStatus.addInfo(RefactoringCoreMessages.ReorgPolicyFactory_noJavaUpdates);

	return superStatus;
}
 
Example 5
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected RefactoringStatus verifyDestination(IJavaElement destination) throws JavaModelException {
	RefactoringStatus superStatus= super.verifyDestination(destination);
	if (superStatus.hasFatalError()) {
		return superStatus;
	}

	Object commonParent= new ParentChecker(getResources(), getJavaElements()).getCommonParent();
	if (destination.equals(commonParent)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	}
	IContainer destinationAsContainer= getDestinationAsContainer();
	if (destinationAsContainer != null && (destinationAsContainer.equals(commonParent) || commonParent instanceof IPackageFragmentRoot
			&& destinationAsContainer.equals(((IPackageFragmentRoot) commonParent).getResource()))) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	}
	IPackageFragment destinationAsPackage= getDestinationAsPackageFragment();
	if (destinationAsPackage != null && (destinationAsPackage.equals(commonParent))) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_parent);
	}

	if (cannotUpdateReferencesForDestination()) {
		superStatus.addInfo(RefactoringCoreMessages.ReorgPolicyFactory_noJavaUpdates);
	}

	return superStatus;
}
 
Example 6
Source File: TmfExperimentElement.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private void deleteTraceResource(IResource resource) throws CoreException {
    resource.delete(true, null);
    IContainer parent = resource.getParent();
    // delete empty folders up to the parent experiment folder
    if (!parent.equals(getResource()) && parent.exists() && parent.members().length == 0) {
        deleteTraceResource(parent);
    }
}
 
Example 7
Source File: ResourceSelectionTree.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private IResource[] getChildResources(IContainer parent) {
	ArrayList children = new ArrayList();
	for (int i = 0; i < resources.length; i++) {
		if (!(resources[i] instanceof IContainer)) {
			IContainer parentFolder = resources[i].getParent();
			if (parentFolder != null && parentFolder.equals(parent) && !children.contains(parentFolder))
				children.add(resources[i]);
		}
	}
	IResource[] childArray = new IResource[children.size()];
	children.toArray(childArray);
	return childArray;
}
 
Example 8
Source File: FileAnalysis.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 获取所有包括分析文件的文件夹(直接包括或间接包括都可)
 * @param rootFolder	起始文件夹
 * @param allFolderList	承装所有文件夹的集合
 */
public void getAllFolder(IContainer rootFolder, List<IContainer> allFolderList){
	
	if (allFolderList == null) {
		allFolderList = new LinkedList<IContainer>();
	}
	IResource[] members;
	try {
		members = rootFolder.members();
		for (IResource resource : members) {
			if (resource instanceof IContainer) {
				boolean faIFilesExsit = false;
				
				//循环判断所有的要分析的文件,检查当前容器下是否包括要分析的文件
				for (int fileIndex = 0; fileIndex < model.getAnalysisIFileList().size(); fileIndex++) {
					IFile ifile = model.getAnalysisIFileList().get(fileIndex);
					
					IContainer iFileParent = ifile.getParent();
					while (iFileParent != null ) {
						if (iFileParent.equals((IContainer)resource) ) {
							faIFilesExsit = true;
							break;
						}else {
							iFileParent = iFileParent.getParent();
						}
					}
					
					//如果当前容器下存在分析的文件,将该容器加载到缓存中,并停止循环其他分析的文件
					if (faIFilesExsit) {
						allFolderList.add((IContainer)resource);
						break;
					}
				}
				
				getAllFolder((IContainer)resource, allFolderList);
			}
		}
	} catch (CoreException e) {
		LOGGER.error("", e);
		e.printStackTrace();
	}
}
 
Example 9
Source File: FileAnalysis.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 获取所有包括分析文件的文件夹(直接包括或间接包括都可)
 * @param rootFolder	起始文件夹
 * @param allFolderList	承装所有文件夹的集合
 */
public void getAllFolder(IContainer rootFolder, List<IContainer> allFolderList){
	
	if (allFolderList == null) {
		allFolderList = new LinkedList<IContainer>();
	}
	IResource[] members;
	try {
		members = rootFolder.members();
		for (IResource resource : members) {
			if (resource instanceof IContainer) {
				boolean faIFilesExsit = false;
				
				//循环判断所有的要分析的文件,检查当前容器下是否包括要分析的文件
				for (int fileIndex = 0; fileIndex < model.getAnalysisIFileList().size(); fileIndex++) {
					IFile ifile = model.getAnalysisIFileList().get(fileIndex);
					
					IContainer iFileParent = ifile.getParent();
					while (iFileParent != null ) {
						if (iFileParent.equals((IContainer)resource) ) {
							faIFilesExsit = true;
							break;
						}else {
							iFileParent = iFileParent.getParent();
						}
					}
					
					//如果当前容器下存在分析的文件,将该容器加载到缓存中,并停止循环其他分析的文件
					if (faIFilesExsit) {
						allFolderList.add((IContainer)resource);
						break;
					}
				}
				
				getAllFolder((IContainer)resource, allFolderList);
			}
		}
	} catch (CoreException e) {
		LOGGER.error("", e);
		e.printStackTrace();
	}
}
 
Example 10
Source File: CopyFilesAndFoldersOperation.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Checks whether the destination is valid for copying the source resources.
 * <p>
 * Note this method is for internal use only. It is not API.
 * </p>
 *
 * @param destination
 *            the destination container
 * @param sourceResources
 *            the source resources
 * @return an error message, or <code>null</code> if the path is valid
 */
public String validateDestination(IContainer destination, IResource[] sourceResources) {
    if (!isAccessible(destination)) {
        return IDEWorkbenchMessages.CopyFilesAndFoldersOperation_destinationAccessError;
    }
    IContainer firstParent = null;
    URI destinationLocation = destination.getLocationURI();
    for (int i = 0; i < sourceResources.length; i++) {
        IResource sourceResource = sourceResources[i];
        if (firstParent == null) {
            firstParent = sourceResource.getParent();
        } else if (firstParent.equals(sourceResource.getParent()) == false) {
            // Resources must have common parent. Fixes bug 33398.
            return IDEWorkbenchMessages.CopyFilesAndFoldersOperation_parentNotEqual;
        }

        URI sourceLocation = sourceResource.getLocationURI();
        if (sourceLocation == null) {
            if (sourceResource.isLinked()) {
                // Don't allow copying linked resources with undefined path
                // variables. See bug 28754.
                return NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_missingPathVariable,
                        sourceResource.getName());
            }
            return NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_resourceDeleted,
                    sourceResource.getName());

        }
        if (sourceLocation.equals(destinationLocation)) {
            return NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_sameSourceAndDest,
                    sourceResource.getName());
        }
        // is the source a parent of the destination?
        if (new Path(sourceLocation.toString()).isPrefixOf(new Path(destinationLocation.toString()))) {
            return IDEWorkbenchMessages.CopyFilesAndFoldersOperation_destinationDescendentError;
        }

        String linkedResourceMessage = validateLinkedResource(destination, sourceResource);
        if (linkedResourceMessage != null) {
            return linkedResourceMessage;
        }
    }
    return null;
}