use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.
the class Java18ProjectTestSetup method createAndInitializeProject.
@Override
protected IJavaProject createAndInitializeProject() throws CoreException {
IJavaProject javaProject = JavaProjectHelper.createJavaProject(PROJECT_NAME18, "bin");
javaProject.setRawClasspath(getDefaultClasspath(), null);
JavaProjectHelper.set18CompilerOptions(javaProject);
return javaProject;
}
use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.
the class IndexSelector method canSeeFocus.
/**
* Returns whether elements of the given project or jar can see the given focus (an IJavaProject or
* a JarPackageFragmentRot) either because the focus is part of the project or the jar, or because it is
* accessible throught the project's classpath
*/
public static int canSeeFocus(SearchPattern pattern, IPath projectOrJarPath) {
try {
IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
IJavaProject project = getJavaProject(projectOrJarPath, model);
IJavaElement[] focuses = getFocusedElementsAndTypes(pattern, project, null);
if (focuses.length == 0)
return PROJECT_CAN_NOT_SEE_FOCUS;
if (project != null) {
return canSeeFocus(focuses, (JavaProject) project, null);
}
// projectOrJarPath is a jar
// it can see the focus only if it is on the classpath of a project that can see the focus
int result = PROJECT_CAN_NOT_SEE_FOCUS;
IJavaProject[] allProjects = model.getJavaProjects();
for (int i = 0, length = allProjects.length; i < length; i++) {
JavaProject otherProject = (JavaProject) allProjects[i];
IClasspathEntry entry = otherProject.getClasspathEntryFor(projectOrJarPath);
if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
int canSeeFocus = canSeeFocus(focuses, otherProject, null);
if (canSeeFocus == PROJECT_CAN_SEE_FOCUS)
return PROJECT_CAN_SEE_FOCUS;
if (canSeeFocus == PROJECT_SOURCE_CAN_NOT_SEE_FOCUS)
result = PROJECT_SOURCE_CAN_NOT_SEE_FOCUS;
}
}
return result;
} catch (JavaModelException e) {
return PROJECT_CAN_NOT_SEE_FOCUS;
}
}
use of org.eclipse.jdt.core.IJavaProject 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.jdt.core.IJavaProject in project che by eclipse.
the class JavaSearchScope method packageFragmentRoot.
/**
* @see AbstractJavaSearchScope#packageFragmentRoot(String, int, String)
*/
public IPackageFragmentRoot packageFragmentRoot(String resourcePathString, int jarSeparatorIndex, String jarPath) {
int index = -1;
boolean isJarFile = jarSeparatorIndex != -1;
if (isJarFile) {
// internal or external jar (case 3, 4, or 5)
String relativePath = resourcePathString.substring(jarSeparatorIndex + 1);
index = indexOf(jarPath, relativePath);
} else {
// resource in workspace (case 1 or 2)
index = indexOf(resourcePathString);
}
if (index >= 0) {
int idx = this.projectIndexes[index];
String projectPath = idx == -1 ? null : (String) this.projectPaths.get(idx);
if (projectPath != null) {
IJavaProject project = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot().getProject(projectPath));
if (isJarFile) {
IResource resource = JavaModel.getWorkspaceTarget(new Path(jarPath));
if (resource != null)
return project.getPackageFragmentRoot(resource);
return project.getPackageFragmentRoot(jarPath);
}
Object target = JavaModel.getWorkspaceTarget(new Path(this.containerPaths[index] + '/' + this.relativePaths[index]));
if (target != null) {
if (target instanceof IProject) {
return project.getPackageFragmentRoot((IProject) target);
}
IJavaElement element = JavaModelManager.create((IResource) target, project);
return (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
}
}
}
return null;
}
use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.
the class JavaModelManager method create.
/**
* Returns the package fragment or package fragment root corresponding to the given folder,
* its parent or great parent being the given project.
* or <code>null</code> if unable to associate the given folder with a Java element.
* <p>
* Note that a package fragment root is returned rather than a default package.
* <p>
* Creating a Java element has the side effect of creating and opening all of the
* element's parents if they are not yet open.
*/
public static IJavaElement create(IFolder folder, IJavaProject project) {
if (folder == null) {
return null;
}
IJavaElement element;
if (project == null) {
project = JavaCore.create(folder.getProject());
element = determineIfOnClasspath(folder, project);
if (element == null) {
// walk all projects and find one that have the given folder on its classpath
IJavaProject[] projects;
try {
projects = org.eclipse.jdt.internal.core.JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects();
} catch (JavaModelException e) {
return null;
}
for (int i = 0, length = projects.length; i < length; i++) {
project = projects[i];
element = determineIfOnClasspath(folder, project);
if (element != null)
break;
}
}
} else {
element = determineIfOnClasspath(folder, project);
}
return element;
}
Aggregations