use of org.eclipse.core.runtime.IPath in project che by eclipse.
the class ZipFileStructureProvider method initialize.
/**
* Initializes this object's children table based on the contents of
* the specified source file.
*/
protected void initialize() {
children = new HashMap(1000);
Enumeration entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entries.nextElement();
if (!entry.isDirectory()) {
IPath path = new Path(entry.getName()).addTrailingSeparator();
int pathSegmentCount = path.segmentCount();
for (int i = 1; i < pathSegmentCount; i++) {
createContainer(path.uptoSegment(i));
}
createFile(entry);
}
}
}
use of org.eclipse.core.runtime.IPath in project che by eclipse.
the class JavaRefactoringDescriptorUtil method setResourcePathArray.
/**
* Inserts the resources into the map.
*
* @param arguments arguments the map with <code><String, String></code> mapping
* @param countAttribute the attribute where the number of resources will be stored. Can be <code>null</code> if no count attribute should be created
* @param arrayAttribute the attribute where the resources will be stored
* @param project the project of the resources or <code>null</code>
* @param resourcePaths the resource paths to store
* @param offset the offset to start at
*
* @throws IllegalArgumentException if the attribute name is invalid or any of the resources are null
*/
public static void setResourcePathArray(Map arguments, String countAttribute, String arrayAttribute, String project, IPath[] resourcePaths, int offset) throws IllegalArgumentException {
if (resourcePaths == null)
//$NON-NLS-1$ //$NON-NLS-2$
throw new IllegalArgumentException("The resources for arrayAttribute '" + arrayAttribute + "' may not be null");
if (countAttribute != null)
setInt(arguments, countAttribute, resourcePaths.length);
for (int i = 0; i < resourcePaths.length; i++) {
IPath resourcePath = resourcePaths[i];
setResourcePath(arguments, getAttributeName(arrayAttribute, offset + i), project, resourcePath);
}
}
use of org.eclipse.core.runtime.IPath in project che by eclipse.
the class IndexSelector method canSeeFocus.
private static int canSeeFocus(IJavaElement focus, JavaProject javaProject, char[][][] focusQualifiedNames) {
try {
if (focus == null)
return PROJECT_CAN_NOT_SEE_FOCUS;
if (focus.equals(javaProject))
return PROJECT_CAN_SEE_FOCUS;
if (focus instanceof JarPackageFragmentRoot) {
// focus is part of a jar
IPath focusPath = focus.getPath();
IClasspathEntry[] entries = javaProject.getExpandedClasspath();
for (int i = 0, length = entries.length; i < length; i++) {
IClasspathEntry entry = entries[i];
if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && entry.getPath().equals(focusPath))
return PROJECT_CAN_SEE_FOCUS;
}
return PROJECT_CAN_NOT_SEE_FOCUS;
}
// look for dependent projects
IPath focusPath = ((JavaProject) focus).getProject().getFullPath();
IClasspathEntry[] entries = javaProject.getExpandedClasspath();
for (int i = 0, length = entries.length; i < length; i++) {
IClasspathEntry entry = entries[i];
if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT && entry.getPath().equals(focusPath)) {
if (focusQualifiedNames != null) {
// builder state is usable, hence use it to try to reduce project which can see the focus...
State projectState = (State) JavaModelManager.getJavaModelManager().getLastBuiltState(javaProject.getProject(), null);
if (projectState != null) {
Object[] values = projectState.getReferences().valueTable;
int vLength = values.length;
for (int j = 0; j < vLength; j++) {
if (values[j] == null)
continue;
ReferenceCollection references = (ReferenceCollection) values[j];
if (references.includes(focusQualifiedNames, null, null)) {
return PROJECT_CAN_SEE_FOCUS;
}
}
return PROJECT_SOURCE_CAN_NOT_SEE_FOCUS;
}
}
return PROJECT_CAN_SEE_FOCUS;
}
}
return PROJECT_CAN_NOT_SEE_FOCUS;
} catch (JavaModelException e) {
return PROJECT_CAN_NOT_SEE_FOCUS;
}
}
use of org.eclipse.core.runtime.IPath in project che by eclipse.
the class IndexSelector method initializeIndexLocations.
/*
* Compute the list of paths which are keying index files.
*/
private void initializeIndexLocations() {
IPath[] projectsAndJars = this.searchScope.enclosingProjectsAndJars();
IndexManager manager = JavaModelManager.getIndexManager();
// use a linked set to preserve the order during search: see bug 348507
LinkedHashSet locations = new LinkedHashSet();
IJavaElement focus = MatchLocator.projectOrJarFocus(this.pattern);
if (focus == null) {
for (int i = 0; i < projectsAndJars.length; i++) {
IPath path = projectsAndJars[i];
Object target = JavaModel.getTarget(path, false);
if (// case of an external folder
target instanceof IFolder)
path = ((IFolder) target).getFullPath();
locations.add(manager.computeIndexLocation(path));
}
} else {
try {
// See whether the state builder might be used to reduce the number of index locations
// find the projects from projectsAndJars that see the focus then walk those projects looking for the jars from projectsAndJars
int length = projectsAndJars.length;
JavaProject[] projectsCanSeeFocus = new JavaProject[length];
SimpleSet visitedProjects = new SimpleSet(length);
int projectIndex = 0;
SimpleSet externalLibsToCheck = new SimpleSet(length);
ObjectVector superTypes = new ObjectVector();
IJavaElement[] focuses = getFocusedElementsAndTypes(this.pattern, focus, superTypes);
char[][][] focusQualifiedNames = null;
boolean isAutoBuilding = ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding();
if (isAutoBuilding && focus instanceof IJavaProject) {
focusQualifiedNames = getQualifiedNames(superTypes);
}
IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
for (int i = 0; i < length; i++) {
IPath path = projectsAndJars[i];
JavaProject project = (JavaProject) getJavaProject(path, model);
if (project != null) {
visitedProjects.add(project);
/*We are adding all modules to the locations for searching in each one.
Now the location contains not only current module and Jars on which depends, but also all modules from the workspace.*/
locations.add(manager.computeIndexLocation(path));
/*int canSeeFocus = canSeeFocus(focuses, project, focusQualifiedNames);
if (canSeeFocus == PROJECT_CAN_SEE_FOCUS) {
locations.add(manager.computeIndexLocation(path));
}
if (canSeeFocus != PROJECT_CAN_NOT_SEE_FOCUS) {
projectsCanSeeFocus[projectIndex++] = project;
}*/
} else {
externalLibsToCheck.add(path);
}
}
for (int i = 0; i < projectIndex && externalLibsToCheck.elementSize > 0; i++) {
IClasspathEntry[] entries = projectsCanSeeFocus[i].getResolvedClasspath();
for (int j = entries.length; --j >= 0; ) {
IClasspathEntry entry = entries[j];
if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
IPath path = entry.getPath();
if (externalLibsToCheck.remove(path) != null) {
Object target = JavaModel.getTarget(path, false);
if (// case of an external folder
target instanceof IFolder)
path = ((IFolder) target).getFullPath();
locations.add(manager.computeIndexLocation(path));
}
}
}
}
// jar files can be included in the search scope without including one of the projects that references them, so scan all projects that have not been visited
if (externalLibsToCheck.elementSize > 0) {
IJavaProject[] allProjects = model.getJavaProjects();
for (int i = 0, l = allProjects.length; i < l && externalLibsToCheck.elementSize > 0; i++) {
JavaProject project = (JavaProject) allProjects[i];
if (!visitedProjects.includes(project)) {
IClasspathEntry[] entries = project.getResolvedClasspath();
for (int j = entries.length; --j >= 0; ) {
IClasspathEntry entry = entries[j];
if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
IPath path = entry.getPath();
if (externalLibsToCheck.remove(path) != null) {
Object target = JavaModel.getTarget(path, false);
if (// case of an external folder
target instanceof IFolder)
path = ((IFolder) target).getFullPath();
locations.add(manager.computeIndexLocation(path));
}
}
}
}
}
}
} catch (JavaModelException e) {
// ignored
}
}
// Ensure no nulls
locations.remove(null);
this.indexLocations = (IndexLocation[]) locations.toArray(new IndexLocation[locations.size()]);
}
use of org.eclipse.core.runtime.IPath in project che by eclipse.
the class JavaSearchScope method encloses.
/* (non-Javadoc)
* @see IJavaSearchScope#encloses(IJavaElement)
*/
public boolean encloses(IJavaElement element) {
if (this.elements != null) {
for (int i = 0, length = this.elements.size(); i < length; i++) {
IJavaElement scopeElement = (IJavaElement) this.elements.get(i);
IJavaElement searchedElement = element;
while (searchedElement != null) {
if (searchedElement.equals(scopeElement))
return true;
searchedElement = searchedElement.getParent();
}
}
return false;
}
IPackageFragmentRoot root = (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
if (root != null && root.isArchive()) {
// external or internal jar
IPath rootPath = root.getPath();
String rootPathToString = rootPath.getDevice() == null ? rootPath.toString() : rootPath.toOSString();
IPath relativePath = getPath(element, true);
return indexOf(rootPathToString, relativePath.toString()) >= 0;
}
// resource in workspace
String fullResourcePathString = getPath(element, false).toString();
return indexOf(fullResourcePathString) >= 0;
}
Aggregations