Search in sources :

Example 1 with ClasspathContainerInitializer

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

the class ReorgCorrectionsSubProcessor method canModifyAccessRules.

private static boolean canModifyAccessRules(IBinding binding) {
    IJavaElement element = binding.getJavaElement();
    if (element == null)
        return false;
    IPackageFragmentRoot root = JavaModelUtil.getPackageFragmentRoot(element);
    if (root == null)
        return false;
    try {
        IClasspathEntry classpathEntry = root.getRawClasspathEntry();
        if (classpathEntry == null)
            return false;
        if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY)
            return true;
        if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            ClasspathContainerInitializer classpathContainerInitializer = JavaCore.getClasspathContainerInitializer(classpathEntry.getPath().segment(0));
            IStatus status = classpathContainerInitializer.getAccessRulesStatus(classpathEntry.getPath(), root.getJavaProject());
            return status.isOK();
        }
    } catch (JavaModelException e) {
        return false;
    }
    return false;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IStatus(org.eclipse.core.runtime.IStatus) JavaModelException(org.eclipse.jdt.core.JavaModelException) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ClasspathContainerInitializer(org.eclipse.jdt.core.ClasspathContainerInitializer) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 2 with ClasspathContainerInitializer

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

the class JavaElementLabels method getContainerEntryLabel.

/**
	 * Returns the label of a classpath container.
	 * The returned label is BiDi-processed with {@link TextProcessor#process(String, String)}.
	 *
	 * @param containerPath the path of the container
	 * @param project the project the container is resolved in
	 * @return the label of the classpath container
	 * @throws JavaModelException when resolving of the container failed
	 */
public static String getContainerEntryLabel(IPath containerPath, IJavaProject project) throws JavaModelException {
    IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, project);
    if (container != null) {
        return Strings.markLTR(container.getDescription());
    }
    ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
    if (initializer != null) {
        return Strings.markLTR(initializer.getDescription(containerPath, project));
    }
    return BasicElementLabels.getPathLabel(containerPath, false);
}
Also used : IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer) ClasspathContainerInitializer(org.eclipse.jdt.core.ClasspathContainerInitializer)

Example 3 with ClasspathContainerInitializer

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

the class JavaElementLabels method getStyledContainerEntryLabel.

/**
	 * Returns the styled label of a classpath container.
	 * The returned label is BiDi-processed with {@link TextProcessor#process(String, String)}.
	 *
	 * @param containerPath the path of the container
	 * @param project the project the container is resolved in
	 * @return the label of the classpath container
	 *
	 * @since 3.4
	 */
public static StyledString getStyledContainerEntryLabel(IPath containerPath, IJavaProject project) {
    try {
        IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, project);
        String description = null;
        if (container != null) {
            description = container.getDescription();
        }
        if (description == null) {
            ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
            if (initializer != null) {
                description = initializer.getDescription(containerPath, project);
            }
        }
        if (description != null) {
            StyledString str = new StyledString(description);
            //				}
            return Strings.markLTR(str);
        }
    } catch (JavaModelException e) {
    // ignore
    }
    return new StyledString(BasicElementLabels.getPathLabel(containerPath, false));
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer) ClasspathContainerInitializer(org.eclipse.jdt.core.ClasspathContainerInitializer)

Example 4 with ClasspathContainerInitializer

use of org.eclipse.jdt.core.ClasspathContainerInitializer 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 5 with ClasspathContainerInitializer

use of org.eclipse.jdt.core.ClasspathContainerInitializer in project bndtools by bndtools.

the class BndContainerInitializer method suggestClasspathContainerUpdate.

/**
     * Suggests whether an update request on the classpath container, if there is one, should be made.
     *
     * @param javaProject
     *            The java project of interest. Must not be null.
     * @throws CoreException
     */
public static boolean suggestClasspathContainerUpdate(IJavaProject javaProject) throws Exception {
    if (getClasspathContainer(javaProject) == null) {
        // project does not have a BndContainer
        return false;
    }
    ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(BndtoolsConstants.BND_CLASSPATH_ID.segment(0));
    if (initializer == null) {
        return false;
    }
    IProject project = javaProject.getProject();
    Updater updater = new Updater(project, javaProject);
    return updater.suggestClasspathContainerUpdate();
}
Also used : ClasspathContainerInitializer(org.eclipse.jdt.core.ClasspathContainerInitializer) IProject(org.eclipse.core.resources.IProject)

Aggregations

ClasspathContainerInitializer (org.eclipse.jdt.core.ClasspathContainerInitializer)14 IClasspathContainer (org.eclipse.jdt.core.IClasspathContainer)8 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)7 IJavaProject (org.eclipse.jdt.core.IJavaProject)7 IProject (org.eclipse.core.resources.IProject)5 IPath (org.eclipse.core.runtime.IPath)5 CoreException (org.eclipse.core.runtime.CoreException)4 JavaModelException (org.eclipse.jdt.core.JavaModelException)3 PluginClasspathContainerInitializer (com.liferay.ide.project.core.PluginClasspathContainerInitializer)2 IFolder (org.eclipse.core.resources.IFolder)2 IWorkspace (org.eclipse.core.resources.IWorkspace)2 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Path (org.eclipse.core.runtime.Path)2 FlexibleProjectContainer (org.eclipse.jst.common.jdt.internal.classpath.FlexibleProjectContainer)2 IFacetedProject (org.eclipse.wst.common.project.facet.core.IFacetedProject)2 IFacetedProjectWorkingCopy (org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy)2 FacetedProjectWorkingCopy (org.eclipse.wst.common.project.facet.core.internal.FacetedProjectWorkingCopy)2 SDK (com.liferay.ide.sdk.core.SDK)1 IOException (java.io.IOException)1