Search in sources :

Example 66 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.

the class JavaModelManager method initializeContainer.

private IClasspathContainer initializeContainer(IJavaProject project, IPath containerPath) throws JavaModelException {
    ClasspathContainerInitializer initializer = containerInitializersCache.get(containerPath.segment(0));
    IClasspathContainer container = null;
    if (initializer != null) {
        // avoid initialization cycles
        containerPut(project, containerPath, CONTAINER_INITIALIZATION_IN_PROGRESS);
        try {
            initializer.initialize(containerPath, project);
            //            if (monitor != null)
            //                monitor.subTask(""); //$NON-NLS-1$
            // retrieve value (if initialization was successful)
            container = containerBeingInitializedGet(project, containerPath);
            if (container == null && containerGet(project, containerPath) == null) {
                // initializer failed to do its job: redirect to the failure container
                container = initializer.getFailureContainer(containerPath, project);
                //                if (container == null) {
                //                    if (CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE)
                //                        verbose_container_null_failure_container(project, containerPath, initializer);
                //                    return null; // break cycle
                //                }
                //                if (CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE)
                //                    verbose_container_using_failure_container(project, containerPath, initializer);
                containerPut(project, containerPath, container);
            }
        } catch (CoreException e) {
            if (e instanceof JavaModelException) {
                throw (JavaModelException) e;
            } else {
                throw new JavaModelException(e);
            }
        }
    } else {
        // create a dummy initializer and get the default failure container
        container = (new ClasspathContainerInitializer() {

            public void initialize(IPath path, IJavaProject javaProject) throws CoreException {
            // not used
            }
        }).getFailureContainer(containerPath, project);
    }
    return container;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) IPath(org.eclipse.core.runtime.IPath) IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer) ClasspathContainerInitializer(org.eclipse.jdt.core.ClasspathContainerInitializer)

Example 67 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.

the class JavaModelManager method createClassFileFrom.

/**
     * Creates and returns a class file element for the given <code>.class</code> file,
     * its project being the given project. Returns <code>null</code> if unable
     * to recognize the class file.
     */
public static IClassFile createClassFileFrom(IFile file, IJavaProject project) {
    if (file == null) {
        return null;
    }
    if (project == null) {
        project = JavaCore.create(file.getProject());
    }
    IPackageFragment pkg = (IPackageFragment) determineIfOnClasspath(file, (JavaProject) project);
    if (pkg == null) {
        // fix for 1FVS7WE
        // not on classpath - make the root its folder, and a default package
        PackageFragmentRoot root = (PackageFragmentRoot) project.getPackageFragmentRoot(file.getParent());
        pkg = root.getPackageFragment(CharOperation.NO_STRINGS);
    }
    return pkg.getClassFile(file.getName());
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IJavaProject(org.eclipse.jdt.core.IJavaProject) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 68 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.

the class JavaModel method getJavaProjects.

/**
 * @see org.eclipse.jdt.core.IJavaModel
 */
public IJavaProject[] getJavaProjects() throws JavaModelException {
    //    ArrayList list = getChildrenOfType(IJavaElement.JAVA_PROJECT);
    // determine my children
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    int length = projects.length;
    IJavaProject[] children = new IJavaProject[length];
    int index = 0;
    for (int i = 0; i < length; i++) {
        IProject project = projects[i];
        if (org.eclipse.jdt.internal.core.JavaProject.hasJavaNature(project)) {
            children[index++] = getJavaProject(project);
        }
    }
    if (index < length)
        System.arraycopy(children, 0, children = new IJavaProject[index], 0, index);
    //    list.toArray(array);
    return children;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IProject(org.eclipse.core.resources.IProject)

Example 69 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.

the class SetContainerOperation method verbose_set_container.

private void verbose_set_container() {
    Util.verbose(//$NON-NLS-1$
    "CPContainer SET  - setting container\n" + "	container path: " + this.containerPath + //$NON-NLS-1$
    '\n' + //$NON-NLS-1$
    "	projects: {" + org.eclipse.jdt.internal.compiler.util.Util.toString(this.affectedProjects, new org.eclipse.jdt.internal.compiler.util.Util.Displayable() {

        public String displayString(Object o) {
            return ((IJavaProject) o).getElementName();
        }
    }) + //$NON-NLS-1$
    "}\n	values: {\n" + org.eclipse.jdt.internal.compiler.util.Util.toString(this.respectiveContainers, new org.eclipse.jdt.internal.compiler.util.Util.Displayable() {

        public String displayString(Object o) {
            //$NON-NLS-1$
            StringBuffer buffer = new StringBuffer("		");
            if (o == null) {
                //$NON-NLS-1$
                buffer.append("<null>");
                return buffer.toString();
            }
            IClasspathContainer container = (IClasspathContainer) o;
            buffer.append(container.getDescription());
            //$NON-NLS-1$
            buffer.append(" {\n");
            IClasspathEntry[] entries = container.getClasspathEntries();
            if (entries != null) {
                for (int i = 0; i < entries.length; i++) {
                    //$NON-NLS-1$
                    buffer.append(" 			");
                    buffer.append(entries[i]);
                    buffer.append('\n');
                }
            }
            //$NON-NLS-1$
            buffer.append(" 		}");
            return buffer.toString();
        }
    }) + //$NON-NLS-1$
    "\n	}");
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer)

Example 70 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project che by eclipse.

the class DeltaProcessor method addDependentProjects.

/*
     * Adds the dependents of the given project to the list of the projects
     * to update.
     */
private void addDependentProjects(IJavaProject project, HashMap projectDependencies, HashSet result) {
    IJavaProject[] dependents = (IJavaProject[]) projectDependencies.get(project);
    if (dependents == null)
        return;
    for (int i = 0, length = dependents.length; i < length; i++) {
        IJavaProject dependent = dependents[i];
        if (result.contains(dependent))
            // no need to go further as the project is already known
            continue;
        result.add(dependent);
        addDependentProjects(dependent, projectDependencies, result);
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject)

Aggregations

IJavaProject (org.eclipse.jdt.core.IJavaProject)743 IProject (org.eclipse.core.resources.IProject)178 IFile (org.eclipse.core.resources.IFile)149 Test (org.junit.Test)146 CoreException (org.eclipse.core.runtime.CoreException)127 JavaModelException (org.eclipse.jdt.core.JavaModelException)124 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)123 IPath (org.eclipse.core.runtime.IPath)110 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)103 ArrayList (java.util.ArrayList)87 IFolder (org.eclipse.core.resources.IFolder)78 IResource (org.eclipse.core.resources.IResource)75 IJavaElement (org.eclipse.jdt.core.IJavaElement)63 IType (org.eclipse.jdt.core.IType)63 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)62 Path (org.eclipse.core.runtime.Path)57 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)56 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)47 StringInputStream (org.eclipse.xtext.util.StringInputStream)39 HashMap (java.util.HashMap)38